当我试图用一个图像来表示一个维吾尔族时,文本并没有显示出来.有没有办法同时显示文本和图像?

推荐答案

你可以用一个既有图像又有文本的自定义视图初始化uibarbuttonite.下面是一个使用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相关问答推荐

将 NSInteger 转换为 NSIndexpath

应用程序终止时处理推送通知

如何使用第一个字符作为部分名称

如何使 UIView 动画序列重复和自动反转

将未知数量的行添加到静态单元UITableView

UITableView/UITableViewCell 点击事件响应?

在 Objective C 中将属性标记为已弃用

performSelector 的返回值:

检测 NSString 的语言

使用 CALayer 时无法编译代码

iOS - 应用程序关闭时的核心位置和地理围栏

[MFMailComposeViewController canSendMail] 什么时候返回 NO

Xcode 在 iOS 8 中的 Main() 中引发异常,并带有所有异常断点

iPhone 上 SQLite 的最佳 Cocoa/Objective-C 包装器库

从 NSString 中删除换行符

将 UIColor 保存到 NSUserDefaults 并从中加载

从视图中删除所有子图层

请求访问相机胶卷的权限

如何使用图像和标签制作自定义 UIBarButtonItem?

Unwind Segue 在 iOS 8 中不起作用