2011-08-16 13 views
3

drawAtPointで複数行テキストを描画する方法はありますか? 私はUILineBreakModeWordWrapを試しましたが、うまく動作していないようですね?drawAtPointを使用した複数行テキスト(ワードラップ)ですか?

このコードを作業用の複数行テキストに変換する方法はありますか?

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

ありがとうございます!

答えて

10

drawAtPoint:は、複数行のテキストをサポートしていません。代わりにdrawInRect:メソッドを使用できます。

編集:(ここに以下@Georgeアズダのコメントをコピー)

[self.heading drawInRect:(contentRect) withFont:mainFont  
     lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; 
+1

これは何か? [self.heading drawInRect:(contentRect)withFont:mainFont lineBreakMode:UILineBreakModeWordWrapアラインメント:UITextAlignmentCenter]; –

+0

はい..まさに.. – EmptyStack

-1

これはNSString drawAtPointメソッドでは実行できません。ドキュメントから:

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

おそらく単純なUILabelを使用できますか?

EDIT

あなたは、このような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; 
+0

私はそれをどのように行うことができますか? (UILabel) –

+0

上記の私の編集を参照してください。 – Mundi

+0

これも正しいでしょうか? [self.heading drawInRect:(contentRect)withFont:mainFont lineBreakMode:UILineBreakModeWordWrapアラインメント:UITextAlignmentCenter]; –

1
[_text drawWithRect:_textRect options:**NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine** attributes:attributes context:nil]; 
+0

コードを説明してください。 – bfontaine

関連する問題