您可以创建一个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;
谢谢,这似乎工作,但标签文本不显示 –
@MaxPuis:我已经更新了我的答案正确设置文字颜色和大小的UILabel。 –