Core Text - Vertical alignment (with multiple lines)

After this question, I figured out how to vertically align the text of one line:

CGRect boundingBox = CTFontGetBoundingBox(font); //Get the position on the y axis float midHeight = self.frame.size.height / 2; midHeight -= boundingBox.size.height / 2; CGPathAddRect(path, NULL, CGRectMake(0, midHeight, self.frame.size.width, boundingBox.size.height)); 

But this code only works for one line context. When a frame generates a line with several lines (with soft or hard line breaks), this code does not work.

+4
source share

All Articles