In my app, I have a navigation bar where I'm using three buttons on the right side. I create it like this:
let button1 = UIBarButtonItem(image: UIImage(named: "button1"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))
// Repeat for button2 and button3
navigationItem.rightBarButtonItems = [button1, button2, button3]
This works as expected, except on iPhone SE. It seems like there is some sort of fixed limit on what percentage of the navigation bar width the right bar buttons can take up, and this limit is exceeded on the small screen of the iPhone SE. So, the rightmost button gets shrunk down to about half the size of the other buttons.
I'm not setting a title, so there's more than enough space for all 3 buttons to be full size - even on iPhone SE. However, I'm not sure how to specify that in code; is there some way to increase this limit (or whatever feature causes the button to shrink) to ensure that all of the BarButtonItems appear full size on iPhone SE?
This isn't the most eloquent way of doing things but it should work.
The iPhone SE
screen's dimensions are w:320 x h:568
Apple Screen Display Sizes
You could possibly resize the images for the iPhone SE and do something like this:
var button1: UIBarButtonItem!
var button2: UIBarButtonItem!
var button2: UIBarButtonItem!
// check the screen's dimensions
if UIScreen.main.bounds.width == 320 && UIScreen.main.bounds.height == 568{
// you may have to play around with it but resize the UIImage(named: "button1") to fit the iPhone SE
button1 = UIBarButtonItem(image: UIImage(named: "button1_Resized"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))
// Repeat for button2 and button3
// resize the UIImage(named: "button2_Resized") and UIImage(named: "button3_Resized") to fit the iPhone SE
} else{
// anything other then the iPhone SE will get the regular sized images
button1 = UIBarButtonItem(image: UIImage(named: "button1"),
style: .plain,
target: self,
action: #selector(self.button1Tapped))
// Repeat for button2 and button3
}
navigationItem.rightBarButtonItems = [button1, button2, button3]