有没有一种用drawAtPoint绘制多行文字的方法?我已经尝试过UILineBreakModeWordWrap,但似乎不起作用?
如何将此代码转换为有效的多行文本??
point = CGPointMake(boundsX, 50);
[self.heading drawAtPoint:point forWidth:labelWidth withFont:mainFont minFontSize:12.0 actualFontSize:NULL lineBreakMode:UILineBreakModeWordWrap baselineAdjustment:UIBaselineAdjustmentAlignBaselines];谢谢!
发布于 2011-08-16 17:57:20
drawAtPoint:不支持多行文本。您可以使用drawInRect:方法。
编辑:(将@George Asda的评论复制到此处)
[self.heading drawInRect:(contentRect) withFont:mainFont
lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];发布于 2015-11-17 15:25:24
[_text drawWithRect:_textRect options:**NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine** attributes:attributes context:nil];发布于 2011-08-16 17:51:23
这不能使用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;https://stackoverflow.com/questions/7076317
复制相似问题