2011-07-26 19 views

Odpowiedz

7
myLabel.textAlignment = UITextAlignmentRight; 

iOS Developer Library jest dobrym źródłem informacji.

+14

UITextAlignmentRight jest przestarzałe od iOS6. Zamiast tego użyj NSTextAlignmentRight. – jbandi

+0

'UITextAlignmentRight' lub' NSTextAlignmentRight' tylko w prawo wyrównanie tekstu, ale tekst nie jest uzasadniony zobacz @Hashem Aboonajmi lub @Aryan odpowiedzi –

1

może to być przez budowniczy interfejsu. lub label.textAlignment = UITextAlignmentRight;

3

Powyższe metody zostały uznane za przestarzałe. Nowe wywołanie metody jest:

label.textAlignment = NSTextAlignmentRight; 
3

Należy ustawić wyrównanie tekstu do uzasadnionego i zestaw nadana bazowej ciąg kierunku pisania do 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

Tu jest: być ostrożnym, jeśli pełny uzasadnić musi być stosowana , firstLineIndent nie powinno być zero.

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]; 
Powiązane problemy