UISplitViewController中的自定义UINavigationbar
问题描述:
在自定义UINavigationController时遇到了一些问题。大小更改正在工作,但(1px * 60px)图像不起作用。代码位于MasterViewController中。UISplitViewController中的自定义UINavigationbar
任何想法?
@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
答
在iOS 5中,所述
UINavigationBar
,UIToolbar
,和UITabBar
实现已经改变,使得除非它是在子类中实现的方法drawRect:
不调用。重新实施drawRect:
在任何这些类别的类别中的应用程序都会发现不调用drawRect:
方法。 UIKit会执行链接检查,以防止iOS 5之前链接的应用程序中调用该方法,但不支持iOS 5或更高版本中的此设计。应用程序可以是:
- 在iOS 5及更高版本中使用自定义API,这是首选方式。
- 子类
UINavigationBar
(或其他栏类)并覆盖子类中的drawRect:
。