cruelty cruelty - 2 years ago 151
Swift Question

Text in between <b></b> programmatic bold string in between and nilling<b></b> UILabel swift

I have core data objects that contain strings that have as markers to make that part of code bold. Is there anyway way of checking for these things in swift making the in between text bold and making the code invisible to the user? I am still new to coding and new to swift language. How would you go about doing this? This is for iOS.

Answer Source
var str = "<b>Hello, playground</b>"
    let atrString = try NSAttributedString(data:str.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil)
    print("Could not convert!")

You will first need to convert the text to NSData using dataUsingEncoding() than try to make a NSAttributedString with an HTML Text document type

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download