我想在我的navigationBar中添加图片,但我无法正确完成。这是代码:
@IBOutlet weak var btnStateChange: UIBarButtonItem!
let buttonState: UIButton = UIButton(type: .Custom)
buttonState.setImage(UIImage(named: "Button-State.png"), forState: UIControlState.Normal)
buttonState.addTarget(self, action: nil, forControlEvents: .TouchUpInside)
buttonState.frame = CGRectMake(0, 0, 22, 22)
let barButton = UIBarButtonItem(customView: buttonState)
self.btnStateChange = barButton
应该看起来像这样:
但我得到了这个结果:
我需要更改代码吗?或者它可能是我使用的PNG?
答案 0 :(得分:1)
如果绿色是png图像的一部分,您可能需要将渲染模式设置为.AlwaysOriginal
的{{1}}。
UIImage