This bug was caused by an inaccessible property of UIButton. Since the button was setup in IB using a system button with a custom icon, it’s imageView property is only accessible in code. The “view” content-mode in IB is misleading here, as it affects the UIButton.view NOT UIButton.ImageView.
- Set content-mode of the buttons imageview to scaleAspectFit.
This commit adds multiple functionalities at once:
- The background of the image title now features rounded corners with a radius of 6 - which is consistent to iOS appearace.
- The background of the image title now is enlarged to make sure the letters do not touch the borders of the view. (This was a finding during implementation).
- The background of the image title is now removed when no title is present (memory optimization / prevention of unwanted optical glitches).
The title label now resizes itself depending on the devices it’s displazed on.
- On iPhone it will take 92% percent of available screen width.
- On iPhone it will 80% of available screen width.
- This works for all device orientations.
The numbers are derived from my personal preference when implementing it.