Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:16:59+00:00 2026-06-13T07:16:59+00:00

I have try to add a two line title bar in UINavigationController I want

  • 0

I have try to add a two line title bar in UINavigationController

I want to adjust font size automatically set according to string length.My String max size goes to 60. I have try to implemented through following code

UILabel *bigLabel = [[UILabel alloc] init];
bigLabel.text = @"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
bigLabel.backgroundColor = [UIColor clearColor];
bigLabel.textColor = [UIColor whiteColor];
bigLabel.font = [UIFont boldSystemFontOfSize:20];
bigLabel.adjustsFontSizeToFitWidth = YES;
bigLabel.clipsToBounds = NO;
bigLabel.numberOfLines = 2;
bigLabel.textAlignment = ([self.title length] < 10 ? NSTextAlignmentCenter : NSTextAlignmentLeft);
[bigLabel sizeToFit];

self.navigationItem.titleView = bigLabel;

It didn’t work for me can you help me please. I have to made this for iPhone and iPad screen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:17:00+00:00Added an answer on June 13, 2026 at 7:17 am

    Just set setNumberOfLines: 0 of UILabel. See the example below.

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setNumberOfLines:0];
    [label setTextColor:[UIColor whiteColor]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setText:@"1234567890 1234567890 1234567890 1234567890 1234567890 123456"];
    self.navigationItem.titleView = label;
    

    enter image description here

    Set Left and Right UIBarButtonItems – you can add them.

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(leftPress:)];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(rightPress:)];
    self.navigationItem.rightBarButtonItem = rightBarButton;
    

    Also decrease the FontSize of Label. It is 12 in this case.
    And it will look like this:

    Enter image description here

    For the extended question:

    Just make some changes in previous code –

    [label setNumberOfLines:2]; //Set it 2 instead of 0
    
    NSString *titleStr = @"3456456676456464554541223434484384233456744444444456785643367";
    
    //Check your string length then set font according to it.
    //I have set font size according to your requirement
    //which is 0-60.
    
    if([titleStr length]>40 && [titleStr length]<=52){
        [label setFont:[UIFont fontWithName:@"Arial" size:13.0]];
    }
    else if([titleStr length]>52){
        [label setFont:[UIFont fontWithName:@"Arial" size:11.5]];
    }
    
    [label setText:titleStr];
    

    Note: You can’t use adjustsFontSizeToFitWidth: property of UILabel, because it doesn’t work for setNumberOfLines:0 in your case you will have to handle it with if condition.

    This is method for set fontSize Of UILabel according to its width.

    [label setNumberOfLines:1];
    label.adjustsFontSizeToFitWidth = YES;
    label.minimumFontSize = 1.0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snipped code: try{ JAXB.xmlJavaConverter(clientCommand); } catch (Exception e){ nServerFifo.add(clientCommand); } I
I am attempting to add some entities that I have created. When I try
I have try to set icon for my App in the xCode. In the
I have try { using (var eventWaitHandle = EventWaitHandle.OpenExisting(name)) { eventWaitHandle.Set(); } Environment.Exit(0); }
I have two classes: class Player { public string Id { set; get; }
I have a big and bloated software and I want to add a new
Hi fellow Androiddevelopers, I try to have two DialogFragments in a row, so when
I have the following code. I get a zero when I try to add
I have two Word documents (WordprocessingDocument), and I want to replace the contents of
I have the result of two request, that contains numbers decimal 8,2. I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.