如何将图像对齐到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)
- }
- }