Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. //
  2. // SGColorExtension.swift
  3. //
  4. // Created by Sudhir Gadhvi on 10/01/19.
  5. // Copyright © 2019 Sudhir. All rights reserved.
  6. //
  7.  
  8. func colorWord(word _word: String, inString _string: String, with _color: UIColor)-> NSMutableAttributedString?
  9. {
  10. let main_string = _string
  11. let string_to_color = _word
  12.  
  13. let range = (main_string as NSString).range(of: string_to_color)
  14.  
  15. let attribute = NSMutableAttributedString.init(string: main_string)
  16. attribute.addAttribute(NSAttributedString.Key.foregroundColor, value: _color , range: range)
  17.  
  18. return attribute
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement