我希望在一个标签中提供这样的输出:
itemNameRight [----- space ---] QtyLeft
实际结果是:
itemNameRightQtyLeft
我不希望UILabel彼此间隔一定的间距,我只想在一个标签中设置它。
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 1.5
paragraphStyle.alignment = NSTextAlignment.left
let priceParagraphStyle = NSMutableParagraphStyle()
priceParagraphStyle.lineSpacing = 1.5
priceParagraphStyle.alignment = NSTextAlignment.right
let itemName = NSMutableAttributedString(string: "itemNameRight")
itemName.addAttribute(NSAttributedStringKey.paragraphStyle,
value:paragraphStyle,
range:NSMakeRange(0, itemName.length))
let itemPrice = NSMutableAttributedString(string: "QtyLeft")
itemPrice.addAttribute(NSAttributedStringKey.paragraphStyle,
value:priceParagraphStyle,
range:NSMakeRange(0, itemPrice.length))