How do I change the vertical alignment of the text in a CTFramesetter frame? I want my text to be in the middle instead of being at the top. I am using Core Text framework. There is a setting of the paragraph to change horizontal aligment but not vertical.
相关问题
- Align typography component to the right
- C++ cout decimal alignment
- dominant-baseline doesn't work in Firefox
- Why should I not use deprecated align='right
- Html Table alignment right
相关文章
- How to use Pandoc image alignment to align two ima
- How do I center the navigation menu?
- Problem while using CTFontRef in a loop to create
- Simple rich text view in cocoa-touch
- How can I determine if a specific emoji character
- How do I avoid merging cells vertically in excel?
- MinGW64 Is Incapable of 32 Byte Stack Alignment (R
- Get unicode character by glyph index in a CTFontRe
This accounts for the fact that multiple font types and styles can be used in a frame (calculates both height and width of text, look in the
if(index == lastLineIndex)
block to see where the height is calculated):Reference: Scott Thompson (http://lists.apple.com/archives/quartz-dev/2008/Mar/msg00079.html)
Finally figured it out ...
You can use [NSString boundingRectWithSize:options:attributes:context:] to get the rectangle of your string's bounding box, which allows multi-line text as well. In your draw text method, do the following (RECT is the rectangle where you want to draw the text):
Thanks Nick, that was a great snippet.
Just expanding on that, if your doing Top, Middle and Bottom alignment with an enum, for example you could do it like so: