The fact is that navigation titleView is always trying to focus your opinion. The reason that the title you see outside the center on the smaller screen is because the width of your custom titleView has exceeded the maximum width of the titleView.
If you set the value to 160, you will see that it is centered for the second situation.
Common decision
If you want to change the title width on different devices, there are several approaches that can help you solve the problem.
Set a different width depending on the width of the screen. For example, when the width of the screen is 320, set it to no more than 160. If the value is greater than 320, assign a value based on a different screen size. This is not an elegant solution, but rather simple, without taking your head apart or posing complex problems.
Calculate the actual width of the titleView. The width of the titleView is determined by the width of the navigation bar minus the left and right barbetton. Sort of
TitleViewWidth = navigation width - leftbarbuttonitem.width +/- rightbarbuttonitem.width - someConstant
You need a little experiment to find a suitable constant that matches this formula.
- Create an xib file for this titleView, adjust the limits more flexibly than a fixed width is required. Download the view from xib and then assign a titleView. It may cost more time to get it working.
Edit
I am thinking of another way that might be easier for you if you are new to this.
In the storyboard, find and drop the view onto this header area of ββthe controller navigation bar.
Show how much time you want to see.
Drop the two shortcuts to this view and set the start and end and vertical and vertical limits.
How does he look on the storyboard

How it works on 4S

source share