-
-
Save MarksCode/139f7203b95bd5f445e653892b4d5553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I want to set a label's text with a string that's partly bold. The words I want to make bold all begin with the same letter, say "~". | |
| For example I could have the string, "This ~word is bold, and so is ~this" | |
| Then the label's text would contain the string "This word is bold, and so is this" where "word" and "this" are bold. | |
| Does anybody know if it's possible to make a function like this? I tried the following: | |
| func makeStringBoldForLabel(str: String) { | |
| var finalStr = "" | |
| let words = str.components(separatedBy: " ") | |
| for var word in words { | |
| if word.characters.first == "~" { | |
| var att = [NSFontAttributeName : boldFont] | |
| let realWord = word.substring(from: word.startIndex) | |
| finalStr = finalStr + NSMutableAttributedString(string:realWord, attributes:att) | |
| } else { | |
| finalStr = finalStr + word | |
| } | |
| } | |
| } | |
| but get the error: | |
| `Binary operator '+' cannot be applied to operands of type 'String' and 'NSMutableAttributedString'` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment