IOS 7 Study - Displaying an Image on a Navigation Bar

Problem
You want to display an image instead of text as the title of the current view controller
on the navigation controller

Solution
Use the titleView property of the view controller’s navigation item

- (void)viewDidLoad {
[super viewDidLoad]; /* Create an Image View to replace the Title View */
UIImageView *imageView =
[[UIImageView alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 40.0f)];
imageView.contentMode = UIViewContentModeScaleAspectFit; /* Load an image. Be careful, this image will be cached */
UIImage *image = [UIImage imageNamed:@"Logo"]; /* Set the image of the Image View */
[imageView setImage:image]; /* Set the Title View */
self.navigationItem.titleView = imageView;
}
上一篇:百度 LBS 开放平台,开发人员众測计划正式启动


下一篇:lintcode:验证二叉查找树