2014-03-04 126 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

相關問題