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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:35:58+00:00 2026-05-16T10:35:58+00:00

I am adjusting my old apps to iPhone 4 using the simulator at the

  • 0

I am adjusting my old apps to iPhone 4 using the simulator at the moment and I can across a very strange behavior with UILabel drawing and sizeWithFont:constrainedToSize: that I currently see only on the iPhone 4 simulator.

I am trying to show the following error text to the user:
@”Incorrect user name or password”
This text sits inside a dynamic error box that is built from three parts: top, center and bottom and therefore I calculate the size of the label so I can change the center background image frame accordingly.

Here is an example of the UILabel size calculation code:

CGRect errorFrame = CGRectMake(40, 0, 240.0, 22.0);
UILabel *errorlabel = [[UILabel alloc] initWithFrame:errorFrame];
errorlabel.adjustsFontSizeToFitWidth = NO;
errorlabel.font = [UIFont fontWithName:@"HelveticaNeue" size:16];
errorlabel.textAlignment = UITextAlignmentLeft;
errorlabel.numberOfLines = 0;
errorlabel.text = @"Incorrect user name or password";
// since only the width is fixed I will use a really large height value
CGSize errorLabelSize = [errorlabel.text sizeWithFont:errorlabel.font constrainedToSize:CGSizeMake(240.0, 4600.0)];
CGRect newFrame = errorlabel.frame;
newFrame.size.height = errorLabelSize.height;
errorlabel.frame = newFrame;
    // added so I can easily see the new frame
errorlabel.backgroundColor = [UIColor redColor];
[self.errorView addSubview:errorlabel];
[errorlabel release];

When I run the code on the iPhone 3 simulator the sizeWithFont:constrainedToSize: method returns a height of 1 line and draws this error text on 1 line.
When I run the same code on the iPhone 4 simulator sizeWithFont:constrainedToSize: returns a size of (170.0, 42.0) which is needed for two lines but label itself is drawn on 1 line.
It is as if the sizeWithFont code doesn’t use the same logics of the rendering code.

Since changing the error text is no option 🙂 any idea how to bypass this issue or resolve it?

Thanks in advance

  • 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-16T10:35:59+00:00Added an answer on May 16, 2026 at 10:35 am

    I’ve got this same problem, with the same font. I haven’t found a way to predict when it will occur, and it appears to never be more than precisely one line extra. It happens on the device exactly as on the simulator. It happens in all of iOS 4.0, 4.0.1, and 4.0.2. I haven’t checked on the 4.1 simulator yet.

    Eventually I worked around by manually noting the places it occurred and subtracting one line height in these locations. When we upgrade to 4.1 we’ll check to see if this behaviour has persisted.

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

Sidebar

Related Questions

When im working with javaScript plugins I often come across this approach for adjusting
I'm very new to python and matplotlib and having trouble with adjusting the height
Fairly new to iPhone/Cocoa development, so I'm having difficulty adjusting. I want to create
Possible Duplicate: Adjusting HttpWebRequest Connection Timeout in C# In my code, I am calling
I'm having trouble adjusting my thinking to suit OpenMP's way of doing things. Roughly,
We are looking at adjusting our web pages so we split our calls for
I am working with a customer on adjusting the speed of their logo carousel,
is anyone aware of a way of adjusting the height of the tab bar
How would I go about dynamically adjusting the height of a UIScrollView ? Basically
Is there a way to shrink what's inside an iframe without adjusting css? any

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.