如何更改UINavigationBar按钮项上的文本颜色 [英] How to change the text color on UINavigationBar button items

查看:78
本文介绍了如何更改UINavigationBar按钮项上的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UINavigationController,我已经使用Interface Builder中的导航栏的Tint属性将其更改为白色。但是按钮和标题中的文本仍然是默认颜色,白色,所以失去了白色背景。

I've got a UINavigationController and i've changed it to white using the Tint property of the navigation bar in Interface Builder. But the text in buttons and the title is still the default color, white, and so gets lost against the white background. Anyone know how to work around this?

推荐答案

从iOS 5开始,使用UIBarButtonItem外观代理更容易:

As of iOS 5 this it much easier, using the UIBarButtonItem appearance proxy:

 NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
                        [UIColor blackColor], 
                        UITextAttributeTextColor, 
                        [UIColor clearColor], 
                        UITextAttributeTextShadowColor, nil];

[[UIBarButtonItem appearance] setTitleTextAttributes: attributes
                                            forState: UIControlStateNormal];

在应用程序中设置:didFinishLaunchingWithOptions:

Set this in application:didFinishLaunchingWithOptions:

这篇关于如何更改UINavigationBar按钮项上的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆