views:

86

answers:

2

What I want is to override UINavigationBar tintColor setter and force default color to it. Bellow is my code (which of course fails). Is there a way to make it work?

@implementation UINavigationBar (UINavigationBarCategory)
- (void)setTintColor:(UIColor *)tint {
self.tintColor = [UIColor greenColor];
}
@end
+1  A: 

If you want to force a default color of a NavigationBar, why don't you set the tint color in viewDidLoad/viewDidAppear of your view controller??

self.navigationController.navigationBar.tintColor = [UIColor (color you want)];
Convolution
Basically, because I have many view controllers and I would like to have only one place where I can set such property for all the navigation bars. Also that would be too easy! :)
sniurkst
+1  A: 

(I'm using property as a generic term here, in your example it's a stand-in for tintColor)

I don't think you can use the self.property = syntax for assignment inside a setProperty: method. self.property is just an alias for [self setProperty:<value>] and it will recursively call itself.

You'll have to do something like this:

- (void)setProperty:(id)pProperty {
     [property autorelease];

     property = [pProperty retain];
}

I'm still not 100% sure what you're trying to do will work, but the preceding is a start.

Frank Schmitt
Thank you for informative answer! I understand the recursive problem of my code and that's why I was interested if there's another way. As for my particular problem I've found another way to force default tint color.
sniurkst