gpt4 book ai didi

objective-c - 我怎样才能拥有一个同时包含图像和文本的 UIBarButtonItem?

转载 作者:IT老高 更新时间:2023-10-28 11:48:05 26 4
gpt4 key购买 nike

当我尝试为 UIBarButtonItem 使用图像时,没有显示文本。有没有办法同时显示文本和图像?

最佳答案

您可以使用包含图像和文本的自定义 View 来初始化 UIBarButtonItem。这是一个使用 UIButton 的示例。

UIImage *chatImage = [UIImage imageNamed:@"08-chat.png"];

UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
[chatButton setBackgroundImage:chatImage forState:UIControlStateNormal];
[chatButton setTitle:@"Chat" forState:UIControlStateNormal];
chatButton.frame = (CGRect) {
.size.width = 100,
.size.height = 30,
};

UIBarButtonItem *barButton= [[[UIBarButtonItem alloc] initWithCustomView:chatButton] autorelease];
self.toolbar.items = [NSArray arrayWithObject:barButton];

关于objective-c - 我怎样才能拥有一个同时包含图像和文本的 UIBarButtonItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3903018/

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