I have created a custom UIButton
class to show the image of the button at the right edge of the screen.
The code is as follows -
class CutomButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
imageView?.translatesAutoresizingMaskIntoConstraints = false
imageView?.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8).isActive = true
imageView?.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
}
}
The above code works as expected. However, the title of the button moves to the right as if the imageView was in its original position (to the left of the title).
Can anyone point out how the title of the button can be placed to its original position as if the image of the button is not present?