Align button image to right edge of UIButton

前端 未结 14 2222
野趣味
野趣味 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:55

    Just like this:

    btn.imageView?.translatesAutoresizingMaskIntoConstraints = false
    btn.imageView?.centerYAnchor.constraint(equalTo: btn.centerYAnchor, constant: 0.0).isActive = true
    btn.imageView?.trailingAnchor.constraint(equalTo: btn.trailingAnchor, constant: 0.0).isActive = true
    btn.imageView?.contentMode = .right
    

提交回复
热议问题