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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:18:15+00:00 2026-05-24T16:18:15+00:00

In CoreText it is easy ask: for a given rectangle how much of this

  • 0

In CoreText it is easy ask: “for a given rectangle how much of this attributed string will fit?”.

CTFrameGetVisibleStringRange(rect).length

Will return where in the string the next run of text should begin.

My question is: “given an attributed string and a width, what rect height do I need to completely bound the attributed string?”.

Does the CoreText framework provide tools to do this?

Thanks,
Doug

  • 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-24T16:18:16+00:00Added an answer on May 24, 2026 at 4:18 pm

    What you need is CTFramesetterSuggestFrameSizeWithConstraints(), you can use it like so:

    CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attributedString)); /*Create your framesetter based in you NSAttrinbutedString*/
    CGFloat widthConstraint = 500; // Your width constraint, using 500 as an example
    CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(
       framesetter, /* Framesetter */
       CFRangeMake(0, text.length), /* String range (entire string) */
       NULL, /* Frame attributes */
       CGSizeMake(widthConstraint, CGFLOAT_MAX), /* Constraints (CGFLOAT_MAX indicates unconstrained) */
       NULL /* Gives the range of string that fits into the constraints, doesn't matter in your situation */
    );
    CGFloat suggestedHeight = suggestedSize.height;
    

    EDIT

    //IMPORTANT: Release the framesetter, even with ARC enabled!
    CFRelease(frameSetter);
    

    As ARC releases only Objective-C objects, and CoreText deals with C, very likely you can have a memory leak here. If your NSAttributedString is small and you do it once, you shouldn’t have any bad consequences. But in a case you have a loop to calculate, let’s say, 50 heights of big/complex NSAttributedStrings, and you don’t release the CTFramesetterRef, you can have serious memory leaks. Check the tutorial linked for more information on memory leaks and debugging with instruments.

    So the solution for this problem is to add CFRelease(frameSetter);

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

Sidebar

Related Questions

Our upcoming app will make extensive use of CoreText. Currently I am unaware of
Before I ask my questions, this is from Apple's documentation re: how to determine
I am drawing text in the view with CoreText. To learn this I used
I have an attributed string that I want to draw bottom-aligned into a rectangular
Working with some CoreText code on iOS and I am confused as to why
I am using CoreText on the iPhone to get italic text in a UIScrollView.
I would like to have a layout similar as this one and also to
I have this error, when I am trying to pass a uitextfeild value from
I need to associate a tag with a CATextLayer so I thought this: .h
I'm using an NSMutableAttribtuedString in order to build a string with formatting, which I

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.