![]() Since I am wanting to change the textColor of multiple Strings I will make a helper function to handle this, but this works for changing the textColor. Let wordRange = stringOneMatch.rangeAtIndex(0)ĪttributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.nameColor(), range: wordRange) Let stringOneMatches = stringOneRegex.matchesInString(longString, options: nil, range: NSMakeRange(0, attributedString.length)) Let stringOneRegex = NSRegularExpression(pattern: nameString, options: nil, error: nil) Var attributedString = NSMutableAttributedString(string:string) ![]() Here is the example of implementation in Swift: let string = "A \(stringOne) and \(stringTwo)" I found my own answer by translating from translating some code fromĬhange attributes of substrings in a NSAttributedString Since I have too low of a rating I can't answer my own question, but here is the answer I found What I need to know is how to find the correct strings from the attributedString, and then change their textColor. TextView.attributedText = attributedStringįrom here I know I need to find the range of words that need to have their textColor changed and then add them to the attributed string. Var attributedString = NSMutableAttributedString(string: string) ![]() What I have so far is something like this: let string = "A \(stringOne) with \(stringTwo)" It appears that what I want to use is NSMutableAttributedString, but I am not finding any resources of how to use this in Swift. I am using a concatenated string, and just want the strings I am appending into the TextView's text. The issue I am having is that I want to be able to change the textColor of certain text in a TextView.
0 Comments
Leave a Reply. |