If you want a button (you probably do want) you can achieve it completely by subclassing UINavigationBar
. You should remember that height
of UINavigationBar
is read-only property.
Style but not tappable:
So let's assume we subclass the navigation bar and add button there. You could do this and it will be going look great. For example:
- (void)drawRect:(CGRect)rect
{
self.backgroundColor = [UIColor lightGrayColor];
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width/2-50, 0 , 100, 100)];
[myButton setBackgroundColor:[UIColor lightGrayColor]];
[myButton setTitle:@"Normal" forState:UIControlStateNormal];
[myButton setTitle:@"Highlighted" forState:UIControlStateHighlighted];
[self addSubview:myButton];
[self sendSubviewToBack:myButton];
}
But you will facing a problem that your button is non tapeable below UINvaigationBar
. (I post an image on the bottom of the answer)
So there is clearly not a path you want to follow. Don't even try that.
Style but not tappable 2:
You may override this method in your navigation bar subclass
- (CGSize) sizeThatFits:(CGSize)size {
return CGSizeMake(custom_width, custom_height);
}
And then mask it using UIBezierPath
for example
The right (tappable) way:
You have to create a view stick to your UINavigationBar
. What i will do here (if you want it to every screen) is:
- Make a Category of
UIViewController
which can draw (for example - this is easiest way) UIButton
.
- Style this 'UIButton' whatever you want (if you want
- Pin action to 'UIButton':
[btn addTarget:self action:@selector(menuShow:) forControlEvents:UIControlEventTouchUpInside];
menuShow:
method should be declare in your category
- You can call drawing button every time you want to redraw view controller.
As you can see there there will be two separates View: UINavigationBar
and UIButton
. This is allow you to set content under this little button and make it tapable.
So why just don't hide navigation bar, and use different view? Because iOS7 ;) When Apple change it in iOS7 for example then you have to rebuild your pseudo NavigationBar, with only additional view, you don't need to do anything.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…