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

后端 未结 3 848
逝去的感伤
逝去的感伤 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:01

    What you can do is use a UICollectionView with cells that have labels that span the entire cell. Each cell then corresponds to individual words. That way you can set either the label or the cell background color to whatever you want.

    For ease of implementation, I would turn your interests variable into an array of strings. That way you can easily count the number of cells you need and give each cell the right string.

提交回复
热议问题