在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