3 回答
TA贡献1936条经验 获得超6个赞
您只需要像这样重载drawRect:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
TA贡献1155条经验 获得超0个赞
乌达夫和列夫劳是对的。这段代码很好地工作:
@interface CustomNavigationBar : UINavigationBar
@end
@implementation CustomNavigationBar
-(void) drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed: @"myNavBarImage"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
// this can go anywhere
+(UINavigationController*) myCustomNavigationController
{
MyViewController *vc = [[[MyViewController alloc] init] autorelease];
UINavigationController *nav = [[[NSBundle mainBundle] loadNibNamed:@"CustomNavigationController" owner:self options:nil] objectAtIndex:0];
nav.viewControllers = [NSArray arrayWithObject:vc];
return nav;
}
您必须创建CustomNavigationController.xib并将UINavigationController放入其中,然后将navigationBar类更改为“ CustomNavigationBar”。
- 3 回答
- 0 关注
- 579 浏览
添加回答
举报