[英]change navigation bar button item color in ios6
I want to change navigation bar back button color for iOS6, I try my best but can't got success. 我想更改iOS6导航栏后退按钮的颜色,我尽力而为,但是没有成功。 So please can any one help me to find out perfect solution?
因此,请任何人可以帮助我找出理想的解决方案吗?
I want to make this button background black. 我想将此按钮背景设为黑色。
I had used 我曾经用过
[[UIBarButtonItem appearance]setTintColor:[UIColor blackColor]];
but it doesn't work. 但这不起作用。 I had also used this one too:
我也曾经用过这个:
[[[self navigationController] navigationBar] setBarTintColor:[UIColor blackColor]];
but got this error: 但是出现了这个错误:
Terminating app due to uncaught exception
NSInvalidArgumentException', reason: '-[UINavigationBar setBarTintColor:]: unrecognized selector sent to instance 0x9d2ab30
in iOS 6
在
iOS 6
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
in ios7 在ios7中
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
another choice 另一种选择
//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];
}
Try this 尝试这个
// UIBarItem appearance // 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];
// using image //使用图片
[[UIBarButtonItem appearance] setBackgroundImage:doneBackgroundImage
forState:UIControlStateNormal
style:UIBarButtonItemStyleDone
barMetrics:UIBarMetricsDefault];
Try this 尝试这个
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.