How to copy the back button?

I understand that the only way to change the color of the button text back is to create your own button:

self.navigationItem.backBarButtonItem = yourCustomBackButton; 

My question is: how to create a back button that takes into account the hue of the color and looks exactly the same as the default back button, except for the text color (if it is not white)?

+4
source share
2 answers

Add a category to the UINavigationBar and set the background color there. This code also shows how to use the image.

 @implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { /*** // use a custom color UIColor *color = [UIColor colorWithRed:.455 green:.365 blue:0 alpha:.9]; 3 CGContextRef context = UIGraphicsGetCurrentContext(); 4 CGContextSetFillColor(context, CGColorGetComponents( [color CGColor])); 5 CGContextFillRect(context, rect); 6 self.tintColor = color; ***/ // use a custom background image UIImage *img = [UIImage imageNamed: [PlistVariables sharedInstance].navbarBackgroundImageName ]; [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; self.tintColor = [PlistVariables sharedInstance].navbarTintColor; } 

Here is an example output using RGB 192.93.0 for a brown background:

enter image description here

+2
source

Unable to change the text color of the back button. However, you can assign a custom view to the leftBarButtonItem property. I put together a simple little project showing how to do this, which recreates the input / output animation of the standard iOS user interface. It does a bit of hacking, but you should be able to assign a button with a label in it for a custom view and update it.

https://github.com/typeoneerror/BBCustomBackButtonViewController

0
source

All Articles