7

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!

maxluzuriaga
  • 1,327
  • 9
  • 16
  • Did you figure this out? I have the exact same problem. – danbretl Oct 12 '12 at 21:51
  • Well, I submitted a ticket to Apple, and after a while they came back with "UILabel can't really do what you're asking," due to some technical reason. I haven't really found a work around, and decided to change the design of this project for other reasons that made this issue irrelevant. Sorry! – maxluzuriaga Oct 20 '12 at 19:35
  • No problem. Thanks for the update. If I find a reliable workaround I'll post an answer. It's not clipping too badly for me most of the time, so I'm not investing much time into it at the moment. – danbretl Oct 21 '12 at 20:04

3 Answers3

1

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.

jszumski
  • 7,430
  • 11
  • 40
  • 53
0

Can you access the clipToBounds or adjustsFontSizeToFitWidth property of the UILabel?

Alternatively you could choose a font size that made the label fin in the UILabel view. A description is available on how to adjust the font size to a given rect here:

How to adjust font size of label to fit the rectangle?

Community
  • 1
  • 1
Niels Castle
  • 8,039
  • 35
  • 56
0

If you are using a navigation controller you can set the titleView of a certain UIViewController that is being displayed. This title view can be a UIImageView with the title as a .png resource.

For example:

Inside your UIViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
            self.navigationController.navigationItem.titleView = [[UIImageView alloc] initWithImage:@"yourheader.png"];
    }

    return self;
}

You can play a little with the size of your image to make it fit properly.

Hope this can help.

MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73
vicsonic
  • 83
  • 1
  • 6
  • 2
    I'm aware of this, but in my app the title needs to change for every new view controller, including changing dynamically based on user input, so a static solution like this wouldn't work. – maxluzuriaga Oct 23 '11 at 19:59