被 NSStringDrawingOptions 项目含义混淆

Confused by NSStringDrawingOptions item meaning

iOS7 之后,我们可以使用 - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context 来计算字符串大小,但我对 NSStringDrawingOptions enum.

的注释感到困惑

NSStringDrawingUsesLineFragmentOrigin

表示指定的原点是线段原点,不是基线原点。但是线段原点和基线原点是什么意思。

就像 WWDC 2013 Session 220(高级文本布局和文本工具包效果)PDF 第 95 页。

如果线段原点表示蓝点,基线原点是什么?

From the official documentation

Discussion

If NSStringDrawingUsesLineFragmentOrigin is specified in options, it wraps the string text as needed to make it fit. If the string is too big to fit completely inside the rectangle, the method scales the font or adjusts the letter spacing to make the string fit within the given bounds.

If NSStringDrawingUsesLineFragmentOrigin is not specified in options, the origin of the rectangle is the baseline of the only line. The text will be displayed above the rectangle and not inside of it. For example, if you specify a rectangle starting at 0,0 and draw the string ‘juxtaposed’, only the descenders of the ‘j’ and ‘p’ will be seen. The rest of the text will be on the top edge of the rectangle.

This method draws the line using the attributes specified in the attributed string itself. If newline characters are present in the string, those characters are honored and cause subsequent text to be placed on the next line underneath the starting point.

Special Considerations This method uses the baseline origin by default, so it renders the string as a single line. To render the string in multiple lines, specify NSStringDrawingUsesLineFragmentOrigin in options.