I have a string like this
var str = "@text1 this is good @text1"
Now replace text1
with another string, say t 1
. I am able to replace the text, but i am not able to bold it. I want to bold the new string t 1
, so that the final output will be:
@t 1 this is good @t 1
How can I do it?
All the examples I am seeing are in Objective-C, but I want to do it in Swift.
Thanks in advance.
When you want to assign it to a label:
I extended David West's great answer so that you can input a string and tell it all the substrings you would like to embolden:
And then call it like this:
This will embolden all the substrings you want bolded in your given string
Super easy way to do this.
For more detail click here: https://github.com/iOSTechHub/AttributedString
usage....
two cents...
Swift 3.0
Convert html to string and font change as per your requirement.
If you're working with localised strings, you might not be able to rely on the bold string always being at the end of the sentence. If this is the case then the following works well:
e.g. Query "blah" does not match any items