设置UILabel - 字体通过代码 - 生成错误 - iPhone

Sag*_*ari 10 iphone uilabel uifont

请仔细查看以下代码.因为它完美无缺.尝试添加您的应用程序.它会工作

- (void)viewDidLoad {
[super viewDidLoad];
// title label - tip
UILabel *tmp=[[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; 
tmp.textColor=[UIColor colorWithRed:(14.0/255.0) green:(105.0/255) blue:(128.0/255) alpha:1.0];
[tmp setFont:[UIFont fontWithName:@"Arial" size:18]]; tmp.text=@"sagar";
tmp.backgroundColor=[UIColor clearColor]; [self.view addSubview:tmp]; [tmp release];
}
Run Code Online (Sandbox Code Playgroud)

现在,请仔细查看以下代码.因为它不起作用.看看这两个代码之间没有任何区别.

- (void)viewDidLoad {
[super viewDidLoad];
// title label - tip
UILabel *tmp=[[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; 
tmp.textColor=[UIColor colorWithRed:(14.0/255.0) green:(105.0/255) blue:(128.0/255) alpha:1.0];
[tmp setFont:[UIFont fontWithName:@"Arial Black" size:18]]; tmp.text=@"sagar";
tmp.backgroundColor=[UIColor clearColor]; [self.view addSubview:tmp]; [tmp release];
}
Run Code Online (Sandbox Code Playgroud)

我刚刚提到#Arial Black#而不是#Arial#.

  • 但它不起作用.
  • 是因为iPhone不支持= Arial Black =?

我想知道它为什么不起作用.

iPhone支持多少种不同的字体?

有没有清单?

如何为UILabel或任何控件设置字体名称?(名称中有空格的字体)

在此先感谢您与我分享您的知识.

fbr*_*eto 22

以下是iPhone OS中可用的字体列表.似乎Arial Black不在其中.


小智 12

尝试 @"Arial-BoldMT"

此外,您可以随时自己创建可用字体列表:

for( NSString *familyName in [UIFont familyNames] ) {
  for( NSString *fontName in [UIFont fontNamesForFamilyName:familyName] ) {
    NSLog(@"%@", fontName);
  }
}
Run Code Online (Sandbox Code Playgroud)