gpt4 book ai didi

ios - 如何将图像和标签添加到 UINavigationBar 作为标题?

转载 作者:可可西里 更新时间:2023-11-01 03:06:12 24 4
gpt4 key购买 nike

目前我只知道如何将字符串作为标题:

[self setTitle:@"iOS CONTROL"];

或带有

的图像
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];

但不能同时进行

有解决办法吗?谢谢

最佳答案

您可以创建一个 UIView 并添加任意数量的 subview 。例如:

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;

关于ios - 如何将图像和标签添加到 UINavigationBar 作为标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22171365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com