iOS 导航栏左右 BarButtonItem偏移
2021-12-28 本文已影响0人
MMOTE
iOS7 之后,我们直接在导航栏添加barbuttonItem时候,会有一定偏移量,
比如:
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btnLeft)
这样布局图片出屏幕,左右可多加一个空白按钮
解决方法:
leftBarButtonItems:
let leftItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
leftItem.width = -20
self.navigationItem.leftBarButtonItems = [leftItem,UIBarButtonItem(customView: btnLeft)]
rightBarButtonItems:
let rightItem = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
rightItem.width = -20
self.navigationItem.rightBarButtonItems = [rightItem,UIBarButtonItem(customView: btnRight)]