简体   繁体   中英

Custom UINavigationbar in UISplitViewController

Having some problems with customizing the UINavigationController. The size change is working, but the (1px*60px) image is not working. The code is located in the MasterViewController.

Any ideas?

@implementation UINavigationBar (custom)

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(self.frame.size.width,60);
    return newSize;
}

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"navimg.png"];
    [image drawAsPatternInRect:CGRectMake(0, 0,self.frame.size.width, self.frame.size.height)];
}
@end

From the documentation :

In iOS 5, the UINavigationBar , UIToolbar , and UITabBar implementations have changed so that the drawRect: method is not called unless it is implemented in a subclass. Apps that have re-implemented drawRect: in a category on any of these classes will find that the drawRect: method isn't called. UIKit does link-checking to keep the method from being called in apps linked before iOS 5 but does not support this design on iOS 5 or later. Apps can either:

  • Use the customization API for bars in iOS 5 and later, which is the preferred way.
  • Subclass UINavigationBar (or the other bar classes) and override drawRect: in the subclass.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM