![](/img/trans.png)
[英]Fix UIBarButtonItem with image to bottom toolbar iOS 7 App
[英]Image icon on the right side of UIBarButtonItem on toolbar (iOS)
您可以使用自定义视图初始化UIBarButton。
https://developer.apple.com/reference/uikit/uibarbuttonitem/1617151-init
在自定义视图中,在旁边放一个UILabel
,然后放UIImageView
。
使用归因字符串,然后将图像与字符串一起添加并显示在标题上
// create an NSMutableAttributedString that we'll append everything to
let fullString = NSMutableAttributedString(string: "Start of text")
// create our NSTextAttachment
let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(named: "Icon.png")
// wrap the attachment in its own attributed string so we can append it
let image1String = NSAttributedString(attachment: image1Attachment)
// add the NSTextAttachment wrapper to our full string, then add some more text.
fullString.append(image1String)
fullString.append(NSAttributedString(string: "End of text"))
// draw the result in a label
yourLabel.attributedText = fullString
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.