3

is there a way to draw multiline text with drawAtPoint? I have tried UILineBreakModeWordWrap but doesnt seem to be working?

How would you convert this code to a working multiline text??

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

Thank you!

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 メソッドでは実行できません。ドキュメントから:

指定されたフォントと属性を使用して、現在のグラフィックス コンテキストの指定された位置に文字列を1 行で描画します。

おそらく単純なものを使用できます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 に答える