What do you mean "with rounded label in it"?
i need to create a string with a colored circle before it.
I know that we can attach an image with an attributed string.
So i thought to create an attributed string with a label.
Is it possible?
Yes it is possible.
See details here:
// create an NSMutableAttributedString that we'll append everything to let fullString = NSMutableAttributedString(string: "Start of text") // create our NSTextAttachment let image1Attachment = NSTextAttachment() image1Attachment.image = UIImage(named: "circleIcon.png") // wrap the attachment in its own attributed string so we can append it let image1String = NSAttributedString(attachment: image1Attachment) // add the NSTextAttachment wrapper to our full string, then add some more text. fullString.append(image1String) fullString.append(NSAttributedString(string: "End of text")) // draw the result in a label yourLabel.attributedText = fullString
I dont want to attach an image in attributed string.
As the color code of the circle comes from api,
i need to attach a label and i need to set the backgorund color of the label with the color comes from api.
How to acheive this?
I don't understand
You said : i need to attach a label
when you say label, that's not a UILabel ? Is that simply a string ?
Attach to what ?
Attaching a UILabel inside an attributedString does not make sense.
What you can do is compute an image of a label with a circle, set its backgroundColor programmatically and include in AttributedString as explained before through attachement.
But I understand you don't want that.
So, do you want to attach to the UILabel where the attributedString is displayed ?
Let's try to draw it
| 1 | | attributedString |
1 is the label, with a background color.
Is it what you want ?
If not, please try to draw what you want
Sample String :
" Starting String end String " ( hypen not required in the circle).
i will get the color of the circle from api.
According to the color received from api, i need to change the color of the circle.