2011-07-26 69 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];