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

The Archive Base Latest Questions

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

Before I ask my questions, this is from Apple’s documentation re: how to determine

  • 0

Before I ask my questions, this is from Apple’s documentation re: how to determine the width of a string using Quartz:

If text measurements are important to your application, it is possible
to calculate them using Quartz 2D functions. However, you might first
consider using ATSUI, whose strength is in text layout and
measurement. ATSUI has several functions that obtain text metrics. Not
only can you obtain after-layout text metrics, but in the rare cases
you need them, you can obtain before-layout text metrics. Unlike
Quartz, for which you must perform the calculations yourself, ATSUI
computes the measurements for you. For example, you can obtain the
image bounding rectangle for text by calling the ATSUI function
ATSUMeasureTextImage.

If you decide that Quartz text suits your needs better than ATSUI (or
Cocoa), you can follow these steps to measure the width of text before
Quartz draws it:

  1. Call the function CGContextGetTextPosition to obtain the current text position.
  2. Set the text drawing mode to kCGTextInvisible using the function CGContextSetTextDrawingMode.
  3. Draw the text by calling the function CGContextShowText to draw the text at the current text position.
  4. Determine the final text position by calling the function CGContextGetTextPosition.
  5. Subtract the starting position from the ending position to determine the width of the text.

Here are my questions:

  1. Is this really the best way to determine the width of a string using Core Graphics? It seems flimsy and since my text co-exists with 2D graphical elements, I’d like to use the same context for all rendering. I was hoping there would be some compact method, like:

    CGContextGetTextWidthAndHeight(context, text);
    
  2. I read that ATSUI is outdated and going to be replaced by Core Text. Is that true and if so, is it in iOS?

  • 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-11T19:47:08+00:00Added an answer on May 11, 2026 at 7:47 pm

    On the iPhone SDK, there’s a family of methods on NSString that provide what you want.

    As of iOS 7.0, these methods are:

    - boundingRectWithSize:options:attributes:context:
    - sizeWithAttributes:
    

    On older versions of iOS we had these, now deprecated:

    – sizeWithFont:  
    – sizeWithFont:forWidth:lineBreakMode:  
    – sizeWithFont:constrainedToSize:  
    – sizeWithFont:constrainedToSize:lineBreakMode:  
    – sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I ask this question I would to apologise because of the fact that
I tried to ask this question before but I guess I didnt explain myself
I don't know if this question has been ask before. But I have a
The SO community was right, profiling your code before you ask performance questions seems
Before I ask this, do note: I want this for debugging purposes. I know
I want to ask why we use this keyword before the parameter in an
I wouldn't normally ask questions like this, but I really cant get my head
I started to ask this question and then figured out the answer before submitting
Before I ask my question, I want to mention that I am only today
Before I ask the question let me state that I have attempted to google

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.