简体   繁体   English

导航栏后退按钮颜色

[英]Navigation bar back button color

I am unable to change the color of navigation bar back button. 我无法更改导航栏后退按钮的颜色。 Any help? 有帮助吗? I customized the UINavigationBar class but I'm unable to change the back button color. 我自定义了UINavigationBar类,但我无法更改后退按钮的颜色。

UINavigationBar class code

#import 
#import "UINavigationBar.h"

@interface UINavigationBar ( Category )
{

}

.m file code

- (void) drawRect:(CGRect)rect 
{

    [[UIImage imageNamed:@"top.png"] drawInRect:rect];
    self.tintColor = [UIColor colorWithRed:38 green:65 blue:82 alpha:1];    
}

I'm not able to change the color of the back button. 我无法改变后退按钮的颜色。

Using this you can change the color of all of the navigation buttons: 使用此功能,您可以更改所有导航按钮的颜色:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

Replace redColor with the following to adjust the color of the buttons: 用以下内容替换redColor以调整按钮的颜色:

colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this.

Note: Available for iOS 5 and > 注意:适用于iOS 5和>

用于在导航控制器中更改后退箭头颜色

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0];

You need to use a UIBarButtonItem with a custom view. 您需要将UIBarButtonItem与自定义视图一起使用。 Something like this: 像这样的东西:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button addTarget:target action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"back_button.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"back_button_tap.png"] forState:UIControlStateHighlighted];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

Then you can put the button to the navigation bar, usually in a controller with UINavigationController: 然后你可以将按钮放到导航栏中,通常在带有UINavigationController的控制器中:

self.navigationItem.leftBarButtonItem = buttonItem;

在iOS7中,您应该替换按钮的颜色

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

在swift和iOs 7和8中写道:

 self.navigationController.navigationBar.tintColor = UIColor.whiteColor() //<-- whiteColor is an example!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM