I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below:
From I
This is a great question and even with the solutions provided - it did not resolve the problem on iOS11.
WORKING SOLUTION
If you create a new extension of UIButton:
class BarButton: UIButton {
override var alignmentRectInsets: UIEdgeInsets {
return UIEdgeInsetsMake(0, 16, 0, 16)
}
}
Then when you use it in your layout:
lazy var btnLogin: BarButton = {
let btn = BarButton(type: .custom)
// Add your button settings
btn.widthAnchor.constraint(equalToConstant: self.frame.size.width).isActive = true
btn.heightAnchor.constraint(equalToConstant: 50).isActive = true
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
This solved a very annoying problem, if you have any issues give me a shout.