我正在尝试全局设置UINavigationBar标题的样式。我已成功使用外观对象与许多UI控件但由于某种原因这些标题不会改变...我试图设置字体,字体颜色和大小,但两者都没有工作。我的代码如下。
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
appFontOfSize:24], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
答案 0 :(得分:0)
我在我的应用程序(IOS 7)中做了类似的事情。我使用了以下代码:
NSDictionary * navBarTitleTextAttributes = @{ NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:18.0f]
};
[[UINavigationBar appearance] setTitleTextAttributes:navBarTitleTextAttributes];
实际上,只是使用不同的符号,它几乎是相同的代码。但也许它的工作方式是这样的?你在哪里设置外观?我直接在AppDelegate类中定义它。
答案 1 :(得分:0)
我在iOS 6和7上使用的代码是:
[appearance setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowColor : [UIColor lightGrayColor],
}];
请注意UITextAttribute*