2013-05-20 58 views
2

我遇到问题,我允许用户为我的项目中的标签选择字体,但当用户设置该标签的大小(使用不同的按钮)时,标签将重置为默认字体。我希望能够保留用户应用的字体,同时仍允许用户更改字体大小。任何帮助表示赞赏,谢谢!如何在不更改字体本身的情况下更改uilabel的字体大小?

这里是我的代码..

-(IBAction)setFont{ 

    [userText setFont:[UIFont fontWithName:@"Arial-BoldMT" size:50.0]]; 

//I had to add a size when setting the font or else I got an error 


} 



-(IBAction)setFontSize{ 

    [userText setFont:[UIFont systemFontOfSize:24]]; 

} 

回答

20

只需使用fontWithSize:方法上的标签的当前字体:

- (IBAction)setFontSize { 
    // Keep the same font but change its size to 24 points. 
    UIFont *font = userText.font; 
    userText.font = [font fontWithSize:24]; 
} 
+0

你摇滚!谢谢 :) – Dave123

0

功能[UIFont systemFontOfSize:]将始终返回默认的系统字体。您可以使用您在setFont中调用的相同功能,即[UIFont fontWithName:size:]

相关问题