开发者

In iPhone App How to change fontstyle throughout the App?

In iPhone App I want to change the fontstyle throughout ( in whole App) the App so is there any quicker way of doing that. suppose I want display all font in style "impact" ,

How 开发者_开发百科can I set fontstyle "impact" throughout the app ?

Please Help and Suggest.


The SDK does not allow you to change font settings on an application-wide basis. If you want to change the default font, you have to do it on a per-object basis.

Also, are you sure that this is a good idea? Changing the default font to "Impact" might not have the "impact" you're looking for...


I usually use a Settings.bundle so the user can choose what font they would like to see throughout the app. This is done on a per object basis as Dave suggests.

Per Object:

[myLabel setFont:[UIFont fontWithName:[[NSUserDefaults standardUserDefaults] stringForKey:@"kFontStyle"] 
                                 size:[[NSUserDefaults standardUserDefaults] integerForKey:@"kFontSize"]]];

In a UIWebView:

This is an example of how I use them when loading HTML into a UIWebView

header = [[NSString stringWithFormat:@"<html><head><style>body{background-color:transparent;font-family:%@;font-size:%@px;color:#960000;}</style></head><body><div align='left'><center><img width='290' height='56' src='0%i.jpg'></center><br>",[[NSUserDefaults standardUserDefaults] stringForKey:@"kFontStyle"],[[NSUserDefaults standardUserDefaults] int stringForKey:@"kFontSize"],courseIndex] retain];
footer = @"</font></font></font></div></body></html>";
[myWebView loadHTMLString:[NSString stringWithFormat:@"%@%@%@",header,[courseItem objectForKey:@"Content"],footer] baseURL:[NSURL fileURLWithPath:bundle]];


You could subclass UIFont and override methods like systemFontWithSize: to return your custom font. You could even do this in a category for UIFont. I do agree with Dave though, be careful with custom fonts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜