繁体   English   中英

导航栏后退按钮颜色

[英]Navigation bar 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];    
}

我无法改变后退按钮的颜色。

使用此功能,您可以更改所有导航按钮的颜色:

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

用以下内容替换redColor以调整按钮的颜色:

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

注意:适用于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];

您需要将UIBarButtonItem与自定义视图一起使用。 像这样的东西:

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];

然后你可以将按钮放到导航栏中,通常在带有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