美文网首页
iOS 导航栏左右 BarButtonItem偏移

iOS 导航栏左右 BarButtonItem偏移

作者: MMOTE | 来源:发表于2021-12-28 08:30 被阅读0次

    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)]

    相关文章

      网友评论

          本文标题:iOS 导航栏左右 BarButtonItem偏移

          本文链接:https://www.haomeiwen.com/subject/hzauqrtx.html