UIButton字体大小不会改变

4
我正在更改UIButton的字体大小,但它没有任何影响。
UIButton*headingButton=[UIButton buttonWithType:UIButtonTypeCustom];

headingButton.frame=CGRectMake(182, 4, 450, 42);        

[headingButton setTitleColor:[UIColor colorWithRed:36/255.0 green:71/255.0 blue:113/255.0 alpha:1.0] forState:UIControlStateNormal]; 
2个回答

5
我在这段代码中无法看到您更改字体大小的操作,但是这可以这样完成:
[headingButton.titleLabel setFont:[UIFont fontWithName:<your font name> size:<your desired size>]];

或者

[headingButton.titleLabel setFont:[UIFont fontWithName:systemFontOfSize:<your desired size>]];

更新:还需要检查您设置的字体在应用程序中是否存在,只需执行以下操作即可:
NSLog(@"Font family names: %@", [UIFont familyNames]);
NSLog(@"Fonts in family Myriad Pro : %@", [UIFont fontNamesForFamilyName:@"Myriad Pro"]);

如果字体文件不存在,您需要将OTF文件拖入项目中,并在info.plist中添加“应用程序提供的字体”。

headingButton.titleLabel.setFont =[UIFont fontWithName:@"Myriad Pro Bold" size:24]]; 标题按钮.titleLabel.setFont =[UIFont fontWithName:@"Myriad Pro Bold" size:24]]; - Ali
这不是正确的格式。如果这不是你的问题,请参考我的编辑:[headingButton.titleLabel setFont:[UIFont fontWithName:@"Myriad Pro Bold" size:24]]。 - Bushra Shahid
这可能是因为在iOS中没有这个字体名称,因为当我给出Arial字体名称时它可以工作。 - Ali

0
 btn.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:8.0];

 btn.titleLabel.font =  [UIFont boldSystemFontOfSize:btn.titleLabel.font.pointSize+3];

第一行用于设置字体名称和大小,第二行用于加粗字体


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接