简体   繁体   中英

Adjust font size in Navigation Title

Is there any way to make the font of the title of the navigation bar adjusted with the width?

Same behaviour as a [UILabel setAdjustsFontSizeToFitWidth:YES] .

I'm trying setting the appearance of the NavigationBar, but no success so far.

Try doing something like:

self.navigationItem.titleView = titleLabel;

where titleLabel is a custom UILabel that you've initialized and customized.

Check out this Fontful code , for example.

There's no way to do this with the standard title item. You can still add your custom UILabel to the navigation bar and take care of the title changes.

You can not change the font of title.

Instead try out this..

self.title = @"My title is this.";
    CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont boldSystemFontOfSize:20.0]].width, 44);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:17.0];
    label.textAlignment = UITextAlignmentCenter;
    self.navigationItem.titleView = label;
    label.text = self.title;
    [label release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM