所以我已经能够改变UINavigationBar中主要文本的文本大小和颜色,如下所示:
[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0],
}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
但是,leftbarbuttonitem的字体大小仍然太大。如何引用leftbarbuttonitem以便我可以为其设置文本样式?
我尝过像
这样的东西[UINavigationBar leftBarButtonItem]
[[UINavigationBar navigationItems] leftBarButtonItem]
[[UINavigationBar appearance] leftBarButtonItem]
// and many others
etc...
但xcode一直在抱怨它不存在,我无法引用它。
有人能告诉我如何根据上面的代码设置leftBarButtonItem的文本大小吗?
由于
答案 0 :(得分:0)
以下内容可行:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
请注意,UINavigationBar使用UIBarButtonItem,因此当对象包含在特定视图中时(需要通过它的类引用),您需要设置该对象的样式。这适用于其他几个地方。另一个用例可能是这样,其中A,B和C是3个不同的UINavigationControllers
[[UIBarButtonItem appearanceWhenContainedIn:[A class], [B class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
[[UIBarButtonItem appearanceWhenContainedIn:[C class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
在上面的示例中,UINavigationControllers A& A中的UIBarButtonItems。 B将接收类似的样式,而UINavigationController C的UIBarButtonItems将具有自己独特的样式。