【发布时间】:2012-10-09 21:57:32
【问题描述】:
我正在尝试仅更改我的一个视图控制器的字体大小,因为它适用于更多文本,因此需要比我的其他视图更小的字体大小。我在didFinishLaunchingWithOptions 期间在appdelegate 中设置导航栏属性,然后在viewDidLoad 期间为有问题的视图控制器设置字体。但是,当我返回或前进屏幕时,我对导航栏所做的更改会保留下来,即较小的字体。有没有解决的办法?例如在退出视图时将字体设置为正常?
Cliffsnotes:试图在一个视图控制器中设置字体,但是一旦我设置了它,它就会应用于所有视图控制器。
代码如下:
在 AppDelegate 中:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"QuicksandBold-Regular" size:24.0],
UITextAttributeFont,
nil]];
在视图控制器 viewDidLoad:
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"QuicksandBold-Regular" size:18.0],
UITextAttributeFont,
nil]];
【问题讨论】:
-
我尝试使用您的解决方案编辑标题颜色:
NSDictionary *titleTextAttributes = [[UINavigationBar appearance] titleTextAttributes]; [titleTextAttributes setValue:[UIColor colorWithRed:0.48627454040000001 green:0.050980396570000003 blue:0.13725490870000001 alpha:1] forKey:UITextAttributeTextColor]; [[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];但不起作用:S!
标签: ios xcode uinavigationcontroller uinavigationbar viewdidload