我知道改变“返回”按钮文本颜色的唯一方法是制作自定义按钮:
self.navigationItem.backBarButtonItem = yourCustomBackButton;
我的问题是:如何创建一个后退按钮,考虑到色调并且与默认的后退按钮完全相同,除了文本的颜色(除非它是白色)?
我知道改变“返回”按钮文本颜色的唯一方法是制作自定义按钮:
self.navigationItem.backBarButtonItem = yourCustomBackButton;
在UINavigationBar中添加一个类别,并在那里设置它的背景颜色。这段代码还展示了如何使用图片。
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
/***
// use a custom color
UIColor *color = [UIColor colorWithRed:.455 green:.365 blue:0 alpha:.9];
3 CGContextRef context = UIGraphicsGetCurrentContext();
4 CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
5 CGContextFillRect(context, rect);
6 self.tintColor = color;
***/
// use a custom background image
UIImage *img = [UIImage imageNamed: [PlistVariables sharedInstance].navbarBackgroundImageName ];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [PlistVariables sharedInstance].navbarTintColor;
}
无法更改返回按钮的文本颜色。但是,您可以将自定义视图分配给leftBarButtonItem属性。我已经编写了一个简单的项目,展示了如何重新创建标准iOS UI的进入/退出动画。需要一些技巧,但您应该能够将带有标签的按钮分配给自定义视图并更新它。
https://github.com/typeoneerror/BBCustomBackButtonViewController