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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:14:37+00:00 2026-06-09T06:14:37+00:00

I have 2 attributed strings say ‘A’ and ‘.’ I need to calculate the

  • 0

I have 2 attributed strings say ‘A’ and ‘.’

I need to calculate the height of each of these strings. Currently the height returned is the same for both, it seems to return the maximum possible height for the tallest character in a given font (even if that character isn’t present in the string).

I would like to get the exact pixel height for each of these characters, so that I can resize a view around them that fits the character (glyph) snugly. I’ve tried using CTFramesetterSuggestFrameSizeWithConstraints() and CTLineGetTypographicBounds() but it returns a number similar to the attributed strings size method.

Would appreciate any tips on how to go about doing this!

  • 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-06-09T06:14:38+00:00Added an answer on June 9, 2026 at 6:14 am

    Got there in the end, you can do it like this:

    // Create an attributed string
    CTLineRef line = CTLineCreateWithAttributedString(_string);
    
    // Get an array of glyph runs from the line
    CFArrayRef runArray = CTLineGetGlyphRuns(line);
    
    // loop through each run in the array      
    CTRunRef run = ....
    
    // Get the range of the run         
    CFRange range = CFRangeMake...
    
    // Use CTRunGetImageBounds                                  
    CGRect glyphRect = CTRunGetImageBounds(run, context, range);
    
    // glyphRect now contains the bounds of the glyph run, if the string is just 1 character you have the correct dimensions of that character.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a grid of squares, each with their coordinates (x and
In my action class I have a Map<Long, Set<String>> attribute, named accountsMap. Lets say
I want to turn Model.attribute into Attribute.models. e.g. I currently have Model.first.attribute => string
I have a number of large data files that I included in projects attributed
Let's say I have a class which looks like this : public class MyClass
I have a model, say, Item. I want to store arbitrary amount of attributes
I have a model that has an array of Strings called tags, public class
let's say I have class A and class B. Class A's definition is: ///
say I have the attribute: public class Column_Attribute : Attribute { public string DbType
Say I have use date = r.find('abbr') to get <abbr class="dtstart" title="2012-11-16T00:00:00-05:00">November 16, 2012</abbr>

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.