首页 文章

导航栏后退按钮颜色

提问于
浏览
3

我无法更改导航栏后退按钮的颜色 . 有帮助吗?我自定义了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];    
}

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

5 回答

  • 0

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

    [[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.
    

    Note: Available for iOS 5 and >

  • 0

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

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

    您需要将 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;
    
  • 1

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

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

    在swift和iOs 7和8中写道:

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

相关问题