关于在iOS11上UIBarButtonItem的图标移动的解决方法

在iOS11上我们设置左右UIBarButtonItem的时候,会发现图标会向里面偏移,如果想回到iOS10 上的效果只需要添加两句代码就行:

 // 感觉可有可无
        //        let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        //        spacer.width = 8
        let offset:CGFloat = CGFloat(8)
        switch type {
        case .left:
            button.contentEdgeInsets = UIEdgeInsets(top: 0, left: -offset, bottom: 0, right: offset)
        case .right:
            button.contentEdgeInsets = UIEdgeInsets(top: 0, left: offset, bottom: 0, right: -offset)

        }
        button.translatesAutoresizingMaskIntoConstraints = false

猜你喜欢

转载自blog.csdn.net/qq_30963589/article/details/80984659