Swift:
A small method. Gets a string and returns an NSMutableAttributedString with an underscore attribute over the full length of the string.
func getUnderlinedAttributedString(string string: String) -> NSMutableAttributedString
{
let attributedString = NSMutableAttributedString.init(string: string)
let stringRange = NSMakeRange(0, attributedString.length)
attributedString.beginEditing()
attributedString.addAttribute(NSUnderlineStyleAttributeName, value: 1, range: stringRange)
attributedString.endEditing()
return attributedString
}
source
share