iOS7 之后,我们直接在导航栏添加barbuttonItem时候,会发现有一定偏移量,
比如:
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btnLeft)
这样是不符合大部分的UI布局的,不美观,这样我们就要对此处理一下。
解决方法:
左侧导航栏按钮:
let leftItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
leftItem.width = -15
self.navigationItem.leftBarButtonItems = [leftItem,UIBarButtonItem(customView: btnLeft)]
右侧导航栏按钮:
let rightItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
rightItem.width = -15
self.navigationItem.rightBarButtonItems = [rightItem,UIBarButtonItem(customView: btnRight)]
这样即可解决偏移的问题。
|