2011-07-26 65 views

回答

7
myLabel.textAlignment = UITextAlignmentRight; 

iOS Developer Library是一個很好的資源。

+14

自iOS6以來,UITextAlignmentRight已被棄用。改用NSTextAlignmentRight。 – jbandi

+0

「UITextAlignmentRight」或「NSTextAlignmentRight」只能對齊文本,但文本不正確請參閱@Hashem Aboonajmi或@Aryan回答 –

1

它可以通過接口生成器。 或label.textAlignment = UITextAlignmentRight;

3

以上方法已被棄用。新的方法調用:

label.textAlignment = NSTextAlignmentRight; 
3

你應該設置文本對齊方式對齊並設置屬性串基地書寫方向從右至左:

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];