您的位置:首页 > 产品设计 > UI/UE

UI: 在导航栏显示一张图片

2014-10-11 13:59 351 查看
问题:
在导航控制器的当前视图中的标题中用一张图片代替文本

使用导航项目中视图控制器中 navigation item 的 titleView 属性:

- (void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
/* 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:@"FullSizeLogo.png"];
/* Set the image of the Image View */
[imageView setImage:image];
/* Set the Title View */
self.navigationItem.titleView = imageView;
}


如果你想使用文本,可以使用导航项目的 title 属性。然而,如果要更多控制标题或者要在导航栏简单显示图片或者其他视图,可以使用视图控制器的导航项目中 titleView 属 性。
可以对其赋值任意UIView的子类对象,例如,我们创建了一个image view,并赋值了一个图片给它,然后把它作为导航控制器上当前视图控制器的标题显示出来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: