答案 0 :(得分:0)
我相信您正在尝试从两个不同的字符串创建一个NSMutableAttributedString。但是你应该做的是创建两个独立的NSMutableAttributedString实例 - 一个用于标题,一个用于细节。
答案 1 :(得分:0)
简单易行
如果你使用不同的标题标题和&然后详细说明
// For title
let attrTitleString = NSMutableAttributedString(string: title)
attrTitleString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrTitleString.length))
LBLTitle.attributedText = attrString
// For detail
let attrDetailsString = NSMutableAttributedString(string: details)
attrDetailsString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrDetailsString.length))
LBLDetail.attributedText = attrDetailsString
表示单个标签
let labelString = "\(title)\n\(details)"
let attrString = NSMutableAttributedString(string: labelString)
// Set common attribute for both title & detail (according to your code)
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))
// You can also set differnt attribute for title & details
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(<... set range for title...>))
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(<...Set range for details....>))
<you label instance - LBLTitle or LBLDetail>.attributedText = attrString