This is driving me nuts, I cant find a simple straightforward answer anywhere on how to make a text range bold, underlined with a custom font in Swift 4.
Every page I go to has a portion of the information but it is sending me round in spirals. I find the underline method for Swift 3, doesn't include custom font, the next one says to use the bold font custom version in Swift 4, etc but doesn't include underline. Very frustrating.
So. I have this text
Reset password email has been sent. Didn’t get it? Send again
'Send again' needs to be bold and underlined. Its a complete string, in one UILabel.
Pretty sure the new method uses UIAttributedStringKey.
I know its pretty simple to be fair which is why I've found it frustrating and have lost my patience with it.
Oh, I'm currently on iOS 11, XCode 9.4.1. I am probably going to update in the next couple of days.
Thanks in advance
Edit
Hey dfd, thanks for your comments. This is basically the code I've got (useless in swift 4.0 although working in Swift 3.0 pretty much as I remember using the code perviously.
I've got to declare the font somewhere and also I haven't found code for the bold either but I do have some code for the range and the underline.
Cheers
var text = self.completeText.text
let textRange = NSMakeRange(50, (text?.count)!)
let attributedText = NSMutableAttributedString(string: text!)
let underlineAttribute = [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
attributedText.addAttribute(underlineAttribute)
* Final Edit*
Heres working code.
let label = self.completeText
let labelString = self.completeText.text
let attributedText = NSMutableAttributedString(string: labelString!)
let rangeToUnderline = (labelString! as NSString).range(of: "Send again")
attributedText.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: rangeToUnderline)
I'm going to add the OpenSansBold custom font with these attrs and it should work ok.
Thanks Adrian, thanks for the suggestions everyone else. Much appreciated!
P.S I don't suppose anyone has got a decent reference for attributed strings on Swift 4.1? Would be nice.