如何将图像对齐到UIButton的右侧,以使其在所有设备上保持在右侧。下面的图像显示了一个带有图像(圆形三角形)的UIButton。该图像是iPhone 6的屏幕截图,它适合我想要的方式。但是对于iPhone 6+,图像向左移动了一点,对于iPhone 5,它向右移动,图像显示在UIButton之外。我知道这个原因,那就是我将UIEdgeInsets的左侧设置为300的值,这对于iPhone 6非常完美。所以我的问题是如何在所有iPhone上实现这种外观。谢谢。
我的UIButton代码:
class DropDownButton : UIButton{
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
style()
}
private func style() {
self.titleEdgeInsets.left = 0
self.layer.cornerRadius = 2;
self.setImage(UIImage(named: "Arrow_Close"), forState: UIControlState.Normal)
self.imageEdgeInsets = UIEdgeInsets(top: 0, left: 300, bottom: 0, right: 0)
self.backgroundColor = UIColor(CGColor: "#FFFFFF".CGColor)
self.tintColor = UIColor(CGColor: "#616366".CGColor)
self.titleLabel!.font = UIFont(name: "OpenSans", size: 15)
}
}