我要实现以下设计:https://i.stack.imgur.com/D5kN3.png
如何在按钮文字的中间设置图像/图标?
答案 0 :(得分:0)
您可以使用背景图像并左右设置标签。或者,您可以创建一个新的xib视图,并根据需要扩展UIButton并使用它
答案 1 :(得分:0)
您可以为此使用属性字符串:
// create a NSMutableAttributedString with the text before the image
let beginning = NSMutableAttributedString(string: "Beginning")
// create a NSTextAttachment with the image
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "image.png")
// create an NSMutableAttributedString with the image
let imageString = NSAttributedString(attachment: imageAttachment)
// add the image to the string
beginning.append(imageString)
// create an NSMutableAttributedString with the text after the image
let end = NSAttributedString(string: "End")
beginning.append()
// set the attributed text of the label
label.attributedText = beginning
答案 2 :(得分:0)
我在这里看到2种可能的选择: