3

有没有办法用 drawAtPoint 绘制多行文本?我试过 UILineBreakModeWordWrap 但似乎没有用?

您如何将此代码转换为有效的多行文本?

point = CGPointMake(boundsX, 50);
[self.heading drawAtPoint:point forWidth:labelWidth withFont:mainFont minFontSize:12.0 actualFontSize:NULL lineBreakMode:UILineBreakModeWordWrap baselineAdjustment:UIBaselineAdjustmentAlignBaselines];

谢谢!

4

3 回答 3

10

drawAtPoint:不支持多行文本。您可以改用drawInRect:方法。

编辑:(将@George Asda 的评论复制到此处)

[self.heading drawInRect:(contentRect) withFont:mainFont    
        lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
于 2011-08-16T09:57:20.373 回答
1
[_text drawWithRect:_textRect options:**NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine** attributes:attributes context:nil];
于 2015-11-17T07:25:23.563 回答
-1

NSString使用drawAtPoint 方法无法做到这一点。从文档中:

使用指定的字体和属性在当前图形上下文中的指定点处以单行方式绘制字符串。

你能不能用一个简单的UILabel

编辑

您可以像这样计算 UILabel 的高度:

//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);

CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font 
                    constrainedToSize:maximumLabelSize 
                    lineBreakMode:yourLabel.lineBreakMode]; 

//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;
于 2011-08-16T09:51:22.807 回答