Reputation: 731
I am using swift 3 in ios, and I want my label to have multiple styles.The code is below, I want completionDate to be italic. And I want quanity to be this color e50079, and i want dist to be 511b70, and i want storeName to be italic. How can i do such in ios using swift 3? Thank You
var completionDate = menuItem.completionDate!+"\n"
var quantity = menuItem.quantity!+" "+menuItem.product!
var were = " were"
var dist = menuItem.distributionActivityType!
var storeName = menuItem.storeName!+"-"+menuItem.city!
cell.label1.text = completionDate+""+quantity+""+were+" "+dist+"\n"+storeName
Upvotes: 1
Views: 157
Reputation: 1976
The straight-forward answer to your question would be to indeed use NSAttributedString
s as suggested by Aseider.
It is often easier to create a cell layout with multiple labels, one for each piece of information. You can style each label individually. You can factor the cell layout code into the cell class or use Interface Builder, keeping the code that configures the cell straight-forward and readable. Dealing with attributed strings is harder as you will have to figure out the attribute ranges yourself.
Upvotes: 1