Skip to content

Instantly share code, notes, and snippets.

@frederik-jacques
Created March 10, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederik-jacques/e7891aac1d585eedd218 to your computer and use it in GitHub Desktop.
Save frederik-jacques/e7891aac1d585eedd218 to your computer and use it in GitHub Desktop.
/*
Version one
-> Expected result
String shows Devine rocks, background set to purple for the whole string
Background set to red for the word 'rocks'
-> Got expected result (http://cl.ly/image/2Q1u0D1B0u0V)
*/
let attString = NSMutableAttributedString(string: "Devine rocks");
attString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.purpleColor(), range: NSMakeRange(0, 12));
attString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(7, 5));
/*
Version two
Take exact the same code as above, but remove the purple background attribute for the whole string.
-> Expected result
Only have 'rocks' show up in red
-> Nope ... the background color is ignored. And everything stays white. (http://cl.ly/image/3g1U0p2Q2x36)
*/
let attString = NSMutableAttributedString(string: "Devine rocks");
attString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(7, 5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment