更改ios6中的导航栏按钮项颜色

时间:2014-07-22 09:33:15

标签: ios iphone objective-c ios7 ios6

我想改变iOS6的导航栏后退按钮颜色,我尽我所能但却无法获得成功。那么请任何人帮我找到完美的解决方案吗?

我想让这个按钮背景变黑。

我用过

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

但它不起作用。我也曾经使用过这个:

[[[self navigationController] navigationBar] setBarTintColor:[UIColor blackColor]]; 

但得到了这个错误:

Terminating app due to uncaught exception
NSInvalidArgumentException', reason: '-[UINavigationBar setBarTintColor:]: unrecognized selector sent to instance 0x9d2ab30

3 个答案:

答案 0 :(得分:1)

iOS 6

中的

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
在ios7中

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];

另一种选择

//allocating the bar button
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(popToBack)];

 //assign the bar button to the navigation bar

self.navigationItem.leftBarButtonItem = leftBarButton;

//change the tint color of the bar button item
self.navigationItem.leftBarButtonItem.tintColor=[UIColor colorWithRed:125.0/255.0 green:90.0/255.0 blue:146.0/255.0 alpha:1];  //[UIColor blackColor]


-(void)popToBack
{
[self.navigationController popViewControllerAnimated:YES];
 }

答案 1 :(得分:0)

试试这个

// UIBarItem外观

 [[UIBarButtonItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
 [UIColor colorWithRed:140.0f/255  green:0.0 blue:0.0 alpha:1.0], UITextAttributeTextColor,
 [UIColor whiteColor], UITextAttributeTextShadowColor,
 [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
 [UIFont fontWithName:@"Helvetica neue" size:16.0], UITextAttributeFont,
 nil]
 forState:UIControlStateNormal];

//使用图片

[[UIBarButtonItem appearance] setBackgroundImage:doneBackgroundImage
                                            forState:UIControlStateNormal
                                               style:UIBarButtonItemStyleDone
                                          barMetrics:UIBarMetricsDefault];

答案 2 :(得分:0)

试试这个

  CGRect rectQuestion=CGRectMake(0 , 0, 50, 30);
    UIButton *btnLeft=[[UIButton alloc]init];
    [btnLeft setFrame:rectQuestion];
    [btnLeft setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    [btnLeft setBackgroundColor:[UIColor blackColor]];
    [btnLeft removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
    [btnLeft addTarget:self action:@selector(PopThis) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBar=[[UIBarButtonItem alloc]initWithCustomView:btnLeft];
    self.navigationItem.leftBarButtonItem=leftBar;
    [btnLeft release];
    [leftBar release];
相关问题