Search
Goodies

Social Networks
Designs I Like

Entries in UINavigationBar (2)

Saturday
Nov032012

Customizing UINavigationBar in iOS 5 with strange behaviour

Here is a very strange iOS 5 behaviour (same in iOS 6). I'm customizing the appearance of a UINavigationBar with a UIImage as shown below.

The following code is used at application startup:

The end result is what I expect for the first 4 tabs of my UITabbar items like this:

The lighting comes from the top of the app. But, when selecting the More tab and all the other sections, the UINavigationBar look becomes flipped upside down like this:

Does somebody know why? What could be the cause of this? If you look carefully, the UIImage I'm using is actuallty flipped upside down in order to get the desired result... but when selecting the More UITabbar item and the following section, it gets displayed as it is really in the .png file but it is not the desired result as I ant the lighting to come from the top of the app.

This question was also posted on StackOverflow here: Customize UINavigationBar in iOS 5 strange behaviour

Thursday
Nov102011

UINavigationBar customization under iOS 5 problem

Apple changed the rules with iOS 5 and UINavigationBar customization. Apple now required to do drawRect when subclassing the UINavigationBar instead of implementing a protocol as it was done under iOS 4. See this question on StackOverflow.


I'm putting the final touch to the next release of Ultimate Password Manager but I found out that doing the UINavigationBar customization only works partially. The Apple's proposed way like shown in this small tutorial  is very simple: http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/. Here is my UINavigationBar subclassing. 
//
//  MyCustomNavigationBar.h
//  uPasswords
//
//  Created by Martin Jean-François on 11-11-09.
//  Copyright (c) 2011 TinySofty. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyCustomNavigationBar : UINavigationBar

@end

#import "MyCustomNavigationBar.h"

@implementation MyCustomNavigationBar

- (void)drawRect:(CGRect)rect {
    UIImage *backgroundImage = [UIImage imageNamed:@"NavigationTitleBackground.png"];
CGContextDrawImage(UIGraphicsGetCurrentContext(),
  CGRectMake(0, 0, self.frame.size.width
                                                            self.frame.size.height),
  backgroundImage.CGImage);
}

@end

In Interface Builder, I made the change to all the UINavigation object properties to change it to my newly defined subclass like shown in the following screen shot. 
The solution is working fine. Mostly. My problem is simple. My application is using a Tabbar with nine (9) tabs. The UINavigationBar is effectively customized for the first four (4) only! So it seems that for the "More" tab and the following one, the subclass's method is not being called so the customization isn't done. Why?