How to change the height and width of a button in iOS app using Swift 4.0 which is developed using Swift 3.0

Beginning with iOS 11, views added to toolbars using UIBarButtonItem using UIBarButtonItem(customView:) are now laid out using auto layout. You should add sizing constraints on your button. For example:

button.widthAnchor.constraintEqualToConstant(30.0).isActive = true
button.heightAnchor.constraintEqualToConstant(23.0).isActive = true

Otherwise, auto layout will use the intrinsic content size of your header view which is likely not what you expect.

For more information see the WWDC 2017 session Updating your app for iOS 11.


swift 4:

button.widthAnchor.constraint(equalToConstant: 30.0).isActive = true
button.heightAnchor.constraint(equalToConstant: 20.0).isActive = true

Tags:

Ios

Xcode9

Swift4