【发布时间】:2011-12-01 05:30:08
【问题描述】:
如何将UIBarButtonItem 添加到UIToolbar 中,其中包含文本和图像?看看我展示的示例图像。这正是我想要做的。
【问题讨论】:
标签: iphone objective-c xcode cocoa-touch ipad
如何将UIBarButtonItem 添加到UIToolbar 中,其中包含文本和图像?看看我展示的示例图像。这正是我想要做的。
【问题讨论】:
标签: iphone objective-c xcode cocoa-touch ipad
首先创建一个带有图片和标题的 UIButton。
然后将该按钮添加到 BarButtonItem
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:customButton];
【讨论】:
向工具栏添加自定义按钮 将此属性设置为该按钮 在按钮上添加标签以显示文本
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
【讨论】:
您应该使用UILabel 和UIImage 作为子视图创建UIView。然后用自定义视图创建UIBarButtonItem:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:customView];
【讨论】:
几个参考链接将指导您如何将 UIBarButtonItem 实现为带有文本和图像的 UIToolbar.... 您只需根据您的要求修改代码即可。
【讨论】: