我需要在Swift 2.0中为我的导航栏按钮设置框架
我尝试了这段代码
self.navigationController!.navigationBar.drawRect(CGRectMake(0, 0, 30, 30))
但这行不通
提前致谢
最佳答案
// Swift 3
let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
backButton.setBackgroundImage(UIImage(named: "img"), for: .normal)
backButton.addTarget(self, action: "action:", for: .touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
// Swift 2
let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
backButton.setBackgroundImage(UIImage(named: "img"), forState: .Normal)
backButton.addTarget(self, action: "action:", forControlEvents: .TouchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
关于swift - 快速更改UINavigationBar中的UIBarButtonItem的宽度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34891973/