Align button image to right edge of UIButton

前端 未结 14 2173
野趣味
野趣味 2020-12-07 23:05

There are plenty of threads about aligning a button image according to the title text, but I can\'t find anything about just aligning the image to the right side of the butt

14条回答
  •  有刺的猬
    2020-12-07 23:31

    I found a tricky way Update the constrains for the UIImageView of the Button

    try this

    button.imageView?.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -8.0).isActive = true
    button.imageView?.centerYAnchor.constraint(equalTo: button.centerYAnchor, constant: 0.0).isActive = true
    

    but don't forget to add this to make the constrains effective

    button.translatesAutoresizingMaskIntoConstraints = false
    button.imageView?.translatesAutoresizingMaskIntoConstraints = false
    

提交回复
热议问题