我正在更改 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];
最佳答案
我在这段代码中看不到你正在改变字体大小,但无论如何,这可以这样做:
[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中添加“应用程序提供的字体”
关于iphone - UIButton 字体大小不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6869515/