@implementation UINavigationBar (CustomImage) -(void)drawRect:(CGRect)rect {
CGRect currentRect = CGRectMake(0,0,100,45);
UIImage *image = [UIImage imageNamed:@"ic_launcher.png"];
[image drawInRect:currentRect];
}
@end
更新
只需在您的方法中添加此代码viewDidLoad:
..
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage2.jpg"]]];
self.navigationItem.rightBarButtonItem = item;
并且如果你想在 NavigationBar 的背景中直接设置图像,那么使用下面的线......
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"i_launcher.png"] forBarMetrics:UIBarMetricsDefault];
另请参阅此链接how-to-add-a-customized-image-button-to-uinavigationbar-in-iphone-sdk
我希望这可以帮助你...