Note that there are some explanatory texts on larger screens.

plurals
  1. POCTFramesetterSuggestFrameSizeWithConstraints does not limit result to constrain size
    primarykey
    data
    text
    <p>I use the CTFramesetterSuggestFrameSizeWithConstraints function to define the size, my attributed string will need, but the height I get is smaller than it should be and also the width is bigger than the constrainSize.width parameter. Here is my code:</p> <pre><code>CTTextAlignment textAlignment = kCTLeftTextAlignment; CTLineBreakMode lineBreakMode = kCTLineBreakByWordWrapping; CTParagraphStyleSetting paragraphSettings[] = { { kCTParagraphStyleSpecifierAlignment, sizeof(textAlignment), &amp;textAlignment }, { kCTParagraphStyleSpecifierLineBreakMode, sizeof(lineBreakMode), &amp;lineBreakMode } }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphSettings, sizeof(paragraphSettings) / sizeof(paragraphSettings[0])); NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:[authorString stringByAppendingFormat:@" %@", bodyText]] autorelease]; CTFontRef ctfontAuthor = CTFontCreateWithName((CFStringRef)@"Arial-BoldMT", 14.0, NULL); CTFontRef ctfontBody = CTFontCreateWithName((CFStringRef)@"Arial", 14.0, NULL); [attrString addAttribute:(NSString *)kCTParagraphStyleAttributeName value:(id)paragraphStyle range:NSMakeRange(0, [attrString length])]; [attrString addAttribute:(NSString *)kCTFontAttributeName value:(id)ctfontAuthor range:NSMakeRange(0, [authorString length] + 1)]; [attrString addAttribute:(NSString *)kCTFontAttributeName value:(id)ctfontBody range:NSMakeRange([authorString length] + 1, [bodyText length])]; CFRelease(ctfontAuthor); CFRelease(ctfontBody); CFRelease(paragraphStyle); CFRange fitRange; CGSize result = CGSizeZero; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFMutableAttributedStringRef)attrString); result = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, [authorString length] + [bodyText length] + 1), NULL, size, &amp;fitRange); CFRelease(framesetter); return result;// result is the value I need to be constrained to size (229.0, MAXFLOAT) but sometimes it is 231 and some more </code></pre> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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