myLabel.textAlignment = UITextAlignmentRight;
Run Code Online (Sandbox Code Playgroud)
iOS Developer Library是一个很好的资源.
您应该将文本对齐设置为对齐并将属性字符串基本写入方向设置为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
Run Code Online (Sandbox Code Playgroud)
上述方法已被弃用。新的方法调用是:
label.textAlignment = NSTextAlignmentRight;
Run Code Online (Sandbox Code Playgroud)