我正在尝试以编程方式设置UIBarButtonItem的背景图像。但我的图片被拉伸和平铺了。如何解决这个问题?非常感谢您的帮助。以下是我的代码:
var objectSelected : UIImage!{
didSet{
if objectSelected == nil {
objectSelected = UIImage(named: "line")
}
let insets = UIEdgeInsetsMake(0, 0, 10, 0)
objectSelected.resizableImageWithCapInsets(insets)
objectSelector.setBackgroundImage(objectSelected, forState: UIControlState.Normal, style: UIBarButtonItemStyle.Plain, barMetrics: UIBarMetrics.Default)
}
}
@IBOutlet weak var objectSelector: UIBarButtonItem!