Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut-off title label in UINavigationBar in iOS 5

Using the iOS 5 SDK I'm writing an app that uses a custom, script style font in its UINavigationBar instance. The problem with this font is that, since it is in the script style, its glyphs exceed the bounds. You can see the problem in-app here:

Example image on a device

For a clearer example, you can see my photoshop document here:

Photoshop example

Any idea how I might fix this issue? My first instinct was to set the clipsToBounds property of the UILabel in the UINavigationBar, but there is apparently no apple-approved way to access this object directly. This has plagued me for some time while I was using iOS 5 in beta, so maybe you can help now that the NDA has lifted.

Thanks!

like image 274
maxluzuriaga Avatar asked Oct 19 '11 21:10

maxluzuriaga


1 Answers

You could use UINavigationItem's titleView to set a UILabel with a custom font, and then override setTitle: to update your custom label. If necessary, you could then call sizeToFit on the label or manually update its frame after using sizeWithFont: or any of the other NSString sizing methods.

like image 149
jszumski Avatar answered Nov 20 '22 20:11

jszumski