Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Change font size in navigation bar

AngerikaAngerika Posts: 19Registered Users
How can I change de size of the title in my navigation bar???
Post edited by Angerika on

Replies

  • javid.alimohideenjavid.alimohideen Posts: 298Registered Users
    I haven't tried this yet. But my guess, would be to create a UILabel and set it's font and size and assign it as the titleView of the navigation Item;


    UILabel *bigLabel = [[UILabel alloc] init];
    bibLabel.text = @\"I am BIG\";
    bigLabel.font = [UIFont fontWithName:@\"Arial\" size: 22.0];
    self.navigationItem.titleView = bigLabel;
    [bigLabel release];
  • AngerikaAngerika Posts: 19Registered Users
    I put this code in my loadView method, but it doesn't shows anything :|

    UILabel *bigLabel = [[UILabel alloc] init];
    bigLabel.text = @"I am BIG";
    bigLabel.font = [UIFont fontWithName:@"Arial" size: 22.0];
    self.navigationItem.customTitleView = bigLabel;
    [bigLabel release];
  • javid.alimohideenjavid.alimohideen Posts: 298Registered Users
    Hmmm. I don't have access to my mac right now to test the code.
    Maybe, the font name is not a valid one,
    test it with code below


    UILabel *bigLabel = [[UILabel alloc] init];
    bibLabel.text = @\"I am BIG\";
    bigLabel.font = [UIFont systemFontOfSize:22.0];
    self.navigationItem.titleView = bigLabel;
    [bigLabel release];

    Also, I noticed you are using customTitleView property in setting the navigation item. I don't think that is still available in SDK5, so use the titleView property.

    Make sure, you don't have any warnings. Objective C is dynamically typed, so it's better to
    TREAT WARNINGS AS ERRORS.
  • AngerikaAngerika Posts: 19Registered Users
    This is my code for showing a label in my navigationBar title:

    UILabel *myTitle = [[UILabel alloc] init];
    myTitle.text = @"This is my title";
    self.navigationItem.titleView = myTitle;
    [myTitle release];

    but it doesn't show anything, what's wrong?
  • halushahalusha Posts: 71Registered Users
    Try setting myTitle.frame to something reasonable.
  • javid.alimohideenjavid.alimohideen Posts: 298Registered Users
    If IB was any better, all this could be done with so much ease :(
  • boneheadbonehead Posts: 225Registered Users
    Angerika said:
    This is my code for showing a label in my navigationBar title:

    UILabel *myTitle = [[UILabel alloc] init];
    myTitle.text = @"This is my title";
    self.navigationItem.titleView = myTitle;
    [myTitle release];

    but it doesn't show anything, what's wrong?
    The docs for the UINavigationItem titleView property say that if the nav item's left button is non-nil, the custom title view is not displayed:
    This property is ignored if leftBarButtonItem is not nil.
    So if you have a left button (such as the default "back" button), it's probably ignored.
  • Pedro ValentiniPedro Valentini Posts: 34Registered Users
    I`m using this code to customize title view, its work for me, if you have problem I sugest that try to localize title view in stack of items.. in my case it`s working because topItem is the title view...

    Insert in loadview..


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    [label setFont:[UIFont boldSystemFontOfSize:16.0]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:self.title];
    [self.navigationController.navigationBar.topItem setTitleView:label];
    [label release];
  • ghanalupoghanalupo Posts: 133Registered Users
    Pedro Valentini;31603 said:
    I`m using this code to customize title view, its work for me, if you have problem I sugest that try to localize title view in stack of items.. in my case it`s working because topItem is the title view...

    Insert in loadview..


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    [label setFont:[UIFont boldSystemFontOfSize:16.0]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:self.title];
    [self.navigationController.navigationBar.topItem setTitleView:label];
    [label release];
    Works exactly as required! Thanks for this ;)
  • myemailisjustinmyemailisjustin Posts: 52Registered Users
    ghanalupo;123462 said:
    Works exactly as required! Thanks for this ;)
    It was crashing for me, unless I changed the following line:

    [self.navigationController.navigationBar.topItem setTitleView:label];

    to:

    [self.navigationController.navigationBar.topItem setTitleView:label.text];


    Then it works! Thanks!
    Malus Pumila, LLC

    http://www.maluspumila.net



    God's Bible - http://ww
  • mattskimattski Posts: 1New Users
    javid.alimohideen;7693 said:
    I haven't tried this yet. But my guess, would be to create a UILabel and set it's font and size and assign it as the titleView of the navigation Item;
    You just missed one thing - to size the view. This can be done either with the initWithFrame intialiser, or by calling sizeToFit like this:


    UILabel *bigLabel = [[UILabel alloc] init];
    bigLabel.text = @\"I am BIG\";
    bigLabel.font = [UIFont fontWithName:@\"Arial\" size: 22.0];
    [bigLabel sizeToFit];
    self.navigationItem.titleView = bigLabel;
    [bigLabel release];
  • CeiJayCeiJay Posts: 21Registered Users
    This is your best option:

    // List of Fonts Available on the iPhone - http://ajnaware.wordpress.com/2008/10/24/list-of-fonts-available-on-the-iphone/
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont fontWithName:@\"Helvetica-Bold\" size: 15.0];
    // Optional - label.text = @\"NavLabel\";
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:self.title];
    [label sizeToFit];
    [self.navigationController.navigationBar.topItem setTitleView:label];
    [label release];
  • Ice_2kIce_2k Posts: 148Registered Users
    Here's how I'm doing it:

    - (void)SetNavigationTitle:(NSString*)title AndSubtitle:(NSString*)subtitle
    {
    if (subtitle == nil)
    {
    self.navigationItem.titleView = nil;
    self.navigationItem.title = title;
    return;
    }

    // set the default title anyway, so the next view controllers will have the correct text on their \"back\" button
    self.navigationItem.title = title;

    #define LEFT_OFFSET 15

    // Replace titleView
    CGRect headerTitleSubtitleFrame = CGRectMake(LEFT_OFFSET, 0, 200, 44);
    UIView* _headerTitleSubtitleView = [[UILabel alloc] initWithFrame:headerTitleSubtitleFrame];
    _headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
    _headerTitleSubtitleView.autoresizesSubviews = YES;

    CGRect titleFrame = CGRectMake(LEFT_OFFSET, 2, 160, 24);
    UILabel *titleView = [[UILabel alloc] initWithFrame:titleFrame];
    titleView.backgroundColor = [UIColor clearColor];
    titleView.font = [UIFont boldSystemFontOfSize:20];
    titleView.textAlignment = UITextAlignmentCenter;
    titleView.textColor = [UIColor whiteColor];
    titleView.shadowColor = [UIColor darkGrayColor];
    titleView.shadowOffset = CGSizeMake(0, -1);
    titleView.text = title;
    titleView.adjustsFontSizeToFitWidth = YES;
    [_headerTitleSubtitleView addSubview:titleView];
    [titleView release];

    CGRect subtitleFrame = CGRectMake(LEFT_OFFSET, 24, 160, 44-24);
    UILabel *subtitleView = [[UILabel alloc] initWithFrame:subtitleFrame];
    subtitleView.backgroundColor = [UIColor clearColor];
    subtitleView.font = [UIFont boldSystemFontOfSize:13];
    subtitleView.textAlignment = UITextAlignmentCenter;
    subtitleView.textColor = [UIColor whiteColor];
    subtitleView.shadowColor = [UIColor darkGrayColor];
    subtitleView.shadowOffset = CGSizeMake(0, -1);
    subtitleView.text = subtitle;
    subtitleView.adjustsFontSizeToFitWidth = YES;
    [_headerTitleSubtitleView addSubview:subtitleView];
    [subtitleView release];

    self.navigationItem.titleView = _headerTitleSubtitleView;
    [_headerTitleSubtitleView release];
    }
  • cpcdevcpcdev Posts: 99Registered Users
    mattski;208447 said:
    You just missed one thing - to size the view. This can be done either with the initWithFrame intialiser, or by calling sizeToFit like this:


    UILabel *bigLabel = [[UILabel alloc] init];
    bigLabel.text = @\"I am BIG\";
    bigLabel.font = [UIFont fontWithName:@\"Arial\" size: 22.0];
    [bigLabel sizeToFit];
    self.navigationItem.titleView = bigLabel;
    [bigLabel release];
    How do I set the label in the above code to show no background? With the above code the label has a white background.

    Thanks
  • cpcdevcpcdev Posts: 99Registered Users
    cpcdev;245403 said:
    How do I set the label in the above code to show no background? With the above code the label has a white background.

    Thanks
    ok so I used bigLabel.backgroundColor = [UIColor blueColor]; and that changes the color but how do I set it to show without a background?
  • musicwind95musicwind95 Posts: 365Registered Users
    bigLabel.backgroundColor = [[UIColor alloc] initWithWhite:1.0 alpha:0.0];
    If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!



    [img]http://img.skitch.com/20100829-
  • cpcdevcpcdev Posts: 99Registered Users
    cpcdev;245404 said:
    ok so I used bigLabel.backgroundColor = [UIColor blueColor]; and that changes the color but how do I set it to show without a background?
    fixed it! used "clearColor"
  • pierreabreuppierreabreup Posts: 1New Users
    Pedro Valentini;31603 said:
    I`m using this code to customize title view, its work for me, if you have problem I sugest that try to localize title view in stack of items.. in my case it`s working because topItem is the title view...

    Insert in loadview..


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    [label setFont:[UIFont boldSystemFontOfSize:16.0]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:self.title];
    [self.navigationController.navigationBar.topItem setTitleView:label];
    [label release];
    VLW PELA AJUDA AQUELE ABRA
  • SO9769SO9769 Posts: 2New Users
    javid.alimohideen;7693 said:
    I haven't tried this yet. But my guess, would be to create a UILabel and set it's font and size and assign it as the titleView of the navigation Item;


    UILabel *bigLabel = [[UILabel alloc] init];
    bibLabel.text = @\"I am BIG\";
    bigLabel.font = [UIFont fontWithName:@\"Arial\" size: 22.0];
    self.navigationItem.titleView = bigLabel;
    [bigLabel release];
    Hello,

    How would I change the font size without changing the font?

    Regards
  • baja_yubaja_yu Posts: 6,166Super Moderators, Registered Users
    SO9769;371032 said:
    Hello,

    How would I change the font size without changing the font?

    Regards
    [UIFont systemFontOfSize:22.0];
Sign In or Register to comment.