2011-07-29 115 views
3

我正在更改UIButton字体大小,但它不起作用。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]; 

回答

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中

+0

[headingButton.titleLabel.setFont = [UIFont fontWithName:@“Myriad Pro Bold”size:24]]; – Ali

+0

我已经尝试过这样但不工作 – Ali

+0

这不是正确的格式。使用[headingButton.titleLabel setFont:[UIFont fontWithName:@“Myriad Pro Bold”size:24]];如果这不是你的问题,请参阅我的编辑 –

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

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

第一行中的“通过应用程序提供的字体”设置字体名称和大小和第二线粗体字体