我想将NSFontAttributeName
和NSUnderlineStyleAttributeName
应用于NSMutableAttributedString
。下面是我的代码,但它不起作用。它只应用font属性。如果我删除了font属性,它会应用下划线属性。我不知道如何申请两者。
let font = UIFont(name: "MyriadPro-Semibold", size: 30)
let underlineAttributedString = NSMutableAttributedString(string: "Menu")
let range = NSMakeRange(0, underlineAttributedString.length)
underlineAttributedString.beginEditing()
underlineAttributedString.addAttribute(NSFontAttributeName, value: font!, range: range)
underlineAttributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.StyleSingle.rawValue, range: range)
underlineAttributedString.endEditing()
menuLabel_.attributedText = underlineAttributedString
menuLabel_.textAlignment = .Center
menuLabel_.textColor = UIColor.darkGrayColor()