UILabel - iPhoneでプログラムによるフォント・書体の設定

私のアプリケーションには、次のようなコードがあります。

tmp=[[UILabel alloc] initWithFrame:label1Frame];
tmp.tag=1;
tmp.textColor=[UIColor blackColor];
[tmp setFont:[UIFont fontWithName:@"American Typewriter" size:18]];
tmp.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:tmp];
[tmp release];

今、私は知る必要があります。

======> コードで "Typeface=bold" を設定するにはどうしたらよいのでしょうか?

ソリューション

ファミリー内のboldフォントの名前を使用する必要があります。American Typewriter の bold バージョンがあるかどうかを調べるには、次のように出力してみてください。

[UIFont fontNamesForFamilyName:@"AmericanTypewriter"] 

をコンソールに出力してください。

この場合、"AmericanTypewriter-Bold"を使用する必要があります。

[UIFont fontNamesForFamilyName:@"AmericanTypewriter-Bold"] 
解説 (5)

セッタープロパティを使うのはどうでしょう。

// Create a string  
NSString *text = @"You are getting sleepy.";

// Get a font to draw it in  
UIFont *font = [UIFont boldSystemFontOfSize:28];

// Draw the string  
[text drawInRect:(CGRect)
withFont:font];
解説 (1)

NSLogだけ 欲しいフォントが手に入る。

NSLog(@" %@", [UIFont fontNamesForFamilyName:@"American Typewriter"]);

そして、配列を取得します。

(
    "AmericanTypewriter-CondensedLight",
    "AmericanTypewriter-Light",
    "AmericanTypewriter-Bold",
    AmericanTypewriter,
    "AmericanTypewriter-CondensedBold",
    "AmericanTypewriter-Condensed"
)

Codeで必要なものを使ってください。

UILabel * loading = [[UILabel alloc] initWithFrame:CGRectMake(350, 402, 150, 25)];
    [loading setFont:[UIFont fontWithName:@"AmericanTypewriter-Bold" size:12.0]];
    [loading setTextColor:[UIColor whiteColor]];
    [loading setBackgroundColor:[UIColor clearColor]];
    [loading setText:@"Loading ..."];
    [self.view addSubview:loading];
解説 (0)