I'm trying with NSMutableAttributedString
but not getting perfect resolution and also underline for each string.
Now It's display like this:
But I want like this:
I m trying with this code in tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
for displaying the cell:
let arrSearchTag = search_detail?.value(forKey: "search_tags") as! NSArray
if arrSearchTag.count > 0
{
let str : NSMutableAttributedString = NSMutableAttributedString(string: "")
for string in arrSearchTag
{
let myString = string
let myString1 = " "
let myAttribute = [NSBackgroundColorAttributeName : UIColor.init(red: 94.0/255.0, green: 94.0/255.0, blue: 94.0/255.0, alpha: 1.0)]
let myAttribute1 = [NSBackgroundColorAttributeName : UIColor.clear]
let range = (myString as! NSString).range(of: myString as! String)
let myAttrString = NSMutableAttributedString(string: myString as! String, attributes: myAttribute)
let myAttrString1 = NSMutableAttributedString(string: myString1 , attributes: myAttribute1)
myAttrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: range)
str.append(myAttrString)
str.append(myAttrString1)
}
cell.lblSearchTags.attributedText = str
}