I want to change navigation bar back button color for iOS6, I try my best but can't got success. 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
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
in 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
[[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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.