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 7191037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:38:40+00:00 2026-05-28T19:38:40+00:00

Is it possible to use the autoshrink property in conjunction on multiple lines on

  • 0

Is it possible to use the autoshrink property in conjunction on multiple lines on a UILabel? for example, the large text size possible on 2 available lines.

  • 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-05-28T19:38:41+00:00Added an answer on May 28, 2026 at 7:38 pm

    These people found a solution:

    http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/

    Their solution is as follows:

    int maxDesiredFontSize = 28;
    int minFontSize = 10;
    CGFloat labelWidth = 260.0f;
    CGFloat labelRequiredHeight = 180.0f;
    //Create a string with the text we want to display.
    self.ourText = @"This is your variable-length string. Assign it any way you want!";
    
    /* This is where we define the ideal font that the Label wants to use.
       Use the font you want to use and the largest font size you want to use. */
    UIFont *font = [UIFont fontWithName:@"Marker Felt" size:maxDesiredFontSize];
    
    int i;
    /* Time to calculate the needed font size.
       This for loop starts at the largest font size, and decreases by two point sizes (i=i-2)
       Until it either hits a size that will fit or hits the minimum size we want to allow (i > 10) */
    for(i = maxDesiredFontSize; i > minFontSize; i=i-2)
    {
        // Set the new font size.
        font = [font fontWithSize:i];
        // You can log the size you're trying: NSLog(@"Trying size: %u", i);
    
        /* This step is important: We make a constraint box 
           using only the fixed WIDTH of the UILabel. The height will
           be checked later. */ 
        CGSize constraintSize = CGSizeMake(labelWidth, MAXFLOAT);
    
        // This step checks how tall the label would be with the desired font.
        CGSize labelSize = [self.ourText sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
    
        /* Here is where you use the height requirement!
           Set the value in the if statement to the height of your UILabel
           If the label fits into your required height, it will break the loop
           and use that font size. */
        if(labelSize.height <= labelRequiredHeight)
            break;
    }
    // You can see what size the function is using by outputting: NSLog(@"Best size is: %u", i);
    
    // Set the UILabel's font to the newly adjusted font.
    msg.font = font;
    
    // Put the text into the UILabel outlet variable.
    msg.text = self.ourText;
    

    In order to get this working, a IBOutlet must be assigned in the interface builder to the UILabel.

    “IBOutlet UILabel *msg;”

    All the merit is of the people at 11pixel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to use a url to set background for framelayout ? Example:
Possible Duplicate: Use templates to get an array's size and end address Can someone
Possible Duplicate: Use autorelease when setting a retain property using dot syntax? What is
Is it possible use in-explicit constructing with operators ? Just like in this example
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If
I have recently started looking into Google Charts API for possible use within the
I need a control having these features: It should be possible use it in
Possible Duplicate: Use cases for IdentityHashMap What could be a practical use of the
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the

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.