2011-07-26 5 views

答えて

7
myLabel.textAlignment = UITextAlignmentRight; 

iOS Developer Libraryは良いリソースです。

+14

iIT6以降、UITextAlignmentRightは廃止されました。代わりにNSTextAlignmentRightを使用してください。 – jbandi

+0

'UITextAlignmentRight'または' NSTextAlignmentRight'はテキストを右揃えにしますが、テキストは正当化されません。@Hashem Aboonajmiまたは@Aryan answersを参照してください –

1

これはインターフェイスビルダーを介して行うことができます。 またはlabel.textAlignment = UITextAlignmentRight;

3

上記のメソッドは廃止されました。新しいメソッドの呼び出しは次のとおりです。

label.textAlignment = NSTextAlignmentRight; 
3

あなたはrightToLeftのに方向を書いて正当化し、セット起因する文字列ベースにテキストの配置を設定する必要があります。ここでは

var label: UILabel = ... 
var text: NSMutableAttributedString = ... 
var paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle 
paragraphStyle.alignment = NSTextAlignment.Justified 
paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping 
paragraphStyle.baseWritingDirection = NSWritingDirection.RightToLeft 
text.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, text.length)) 
label.attributedText = text 
2

は次のとおりです。フルを適用する必要性を正当化する場合 は注意が必要、firstLineIndentはゼロであってはなりません。

NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init]; 
paragraph.alignment = NSTextAlignmentJustified; 
paragraph.baseWritingDirection = NSWritingDirectionRightToLeft; 
paragraph.firstLineHeadIndent = 1.0; 
NSDictionary* attributes = @{ 
          NSForegroundColorAttributeName: [UIColor colorWithRed:0.2 green:0.239 blue:0.451 alpha:1],NSParagraphStyleAttributeName: paragraph}; 
NSString* txt = @"your long text"; 
NSAttributedString* aString = [[NSAttributedString alloc] initWithString: txt attributes: attributes]; 
関連する問題