Note that there are some explanatory texts on larger screens.

plurals
  1. POBounding Rectangle using Core Text
    primarykey
    data
    text
    <p>Please correct me if I'm wrong.</p> <p>I tried to work out the exact bounding rectangle of a character using Core Text. But the height I received was always bigger than the actual height of the drawn character on the screen. In this case, the actual height is around 20 but the function just give me 46 no matter what.</p> <p>Could anyone shed some light on this?</p> <p>Thanks.</p> <p>Here is the code </p> <pre><code>- (void)viewDidLoad{ [super viewDidLoad]; NSString *testString = @"A"; NSAttributedString *textString = [[NSAttributedString alloc] initWithString:testString attributes:@{ NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:40] }]; NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:textString]; NSLayoutManager *textLayout = [[NSLayoutManager alloc] init]; // Add layout manager to text storage object [textStorage addLayoutManager:textLayout]; // Create a text container NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:self.view.bounds.size]; // Add text container to text layout manager [textLayout addTextContainer:textContainer]; NSRange range = NSMakeRange (0, testString.length); CGRect boundingBox = [textLayout boundingRectForGlyphRange:range inTextContainer:textContainer]; //BoundingBox:{{5, 0}, {26.679688, 46}} // Instantiate UITextView object using the text container UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20,20,self.view.bounds.size.width-20,self.view.bounds.size.height-20) textContainer:textContainer]; // Add text view to the main view of the view controler [self.view addSubview:textView]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload