Swift how to add background color just around text in a label?

后端 未结 3 945
逝去的感伤
逝去的感伤 2021-01-25 00:23

How do you add a background color around each variable inside the interests variable? Just around text not the spaces.

var interests = \"\\(int01)     \\(int02)          


        
3条回答
  •  甜味超标
    2021-01-25 01:05

    let attributedString = NSMutableAttributedString(string: interests)
    attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(startOfWord, lengthOfWord))
    

提交回复
热议问题