I have a UIButton
with text "Explore the app" and UIImage
(>)
In Interface Builder
it looks like:
[ (>) Explore the app ]
但我需要把这UIImage
放在文本后面:
[ Explore the app (>) ]
我怎样才能把UIImage
移到右边?
I have a UIButton
with text "Explore the app" and UIImage
(>)
In Interface Builder
it looks like:
[ (>) Explore the app ]
但我需要把这UIImage
放在文本后面:
[ Explore the app (>) ]
我怎样才能把UIImage
移到右边?
这是我自己做这件事的方法,(after about 10 years)
class CustomButton: Button {
var didLayout: Bool = false // The code must be called only once
override func layoutSubviews() {
super.layoutSubviews()
if !didLayout, let imageView = imageView, let titleLabel = titleLabel {
didLayout = true
let stack = UIStackView(arrangedSubviews: [titleLabel, imageView])
addSubview(stack)
stack.edgesToSuperview() // I use TinyConstraints library. You could handle the constraints directly
stack.axis = .horizontal
}
}
}