2014-03-04 127 views

回答

13

您可以创建一个UIView并根据需要添加尽可能多的子视图。例如:

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 40.0)]; 
titleView.backgroundColor = [UIColor clearColor]; 

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]]; 

UILabel *titleLabel = [[UILabel alloc] init]; 
titleLabel.backgroundColor = [UIColor clearColor]; 
titleLabel.textColor = [UIColor redColor]; 
titleLabel.text = @"My Title Label"; 
[titleLabel sizeToFit]; 

... 

// Set the frames for imageView and titleLabel to whatever you need them to be 

... 

[titleView addSubview:imageView]; 
[titleView addSubview:titleLabel]; 

self.navigationItem.titleView = titleView; 
+0

谢谢,这似乎工作,但标签文本不显示 –

+0

@MaxPuis:我已经更新了我的答案正确设置文字颜色和大小的UILabel。 –

1

创建一个新的UIView,添加UIImageUILabel作为子视图你想要的方式,并添加UIView使用self.navigationItem.titleView

相关问题