当我尝试为 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/