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

  • Home
  • SEARCH
  • 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 129033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:43:47+00:00 2026-05-11T05:43:47+00:00

In my question How do I get -[NSString sizeWithFont:forWidth:lineBreakMode:] to work? , I learned

  • 0

In my question ‘How do I get -[NSString sizeWithFont:forWidth:lineBreakMode:] to work?‘, I learned that -[NSString sizeWithFont:constrainedToSize:lineBreakMode:] was actually what I needed.

The documentation for -[NSString sizeWithFont:forWidth:lineBreakMode:] states explains it doesn’t actually wrap the text to additional lines. So how would I use it? (Examples would help.)

  • 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. 2026-05-11T05:43:47+00:00Added an answer on May 11, 2026 at 5:43 am

    It works great for multi line strings as well.

    Basically its a function that lets you see how big a string is going to be when rendered with a font and line break mode.

    I use it in a few spots in my application when I have variable length text I want to display in a certain area.

    By default a UILabel will center the text vertically. To have the text top aligned you need to size the label to be only the height required by the string that’s in it.

    I use this method to do this.

    And example of how I would use it to do that is as follows:

    //Calculate the expected size based on the font and linebreak mode of your label CGSize maximumLabelSize = CGSizeMake(296,9999);  CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font                          constrainedToSize:maximumLabelSize                          lineBreakMode:yourLabel.lineBreakMode];   //adjust the label the the new height. CGRect newFrame = yourLabel.frame; newFrame.size.height = expectedLabelSize.height; yourLabel.frame = newFrame; 

    You specify how big of an area you have to put the text in, and then this method tells you how much space it will take up (wrapping as required). Also if the string will overflow the bounds of the rect you provide you can tell and then decided how to display the text.

    The reference to it not actually wrapping the text is there because this method doesn’t actually do anything to the text. It just virtually lays it out and returns how big of an area it would need to really lay it out.

    It’s the responsibility of the label (or what ever container you are using for the text) to perform the wrapping/what ever else that needs to be done.

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

Sidebar

Related Questions

Question I am trying to dynamically get the default for a type that is
I need to solve the following question which i can't get to work by
So this question will get technical – eventually – but first check out Hanselminutes
Without the following: ATL MFC Question: How to get the COM Server , to
This is a bit of a lazyweb question but you get the rep so
The reason for me asking this question is:- I get a real buzz out
I get asked this question a lot and I thought I'd solicit some input
Basically the question is how to get from this: foo_id foo_name 1 A 1
The following question answers how to get large memory pages on Windows : how
I have a Question class: class Question { public int QuestionNumber { get; set;

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.