Skip to content

Instantly share code, notes, and snippets.

@C4Code
Last active August 29, 2015 14:21
Show Gist options
  • Save C4Code/3fb4e036986f34974d78 to your computer and use it in GitHub Desktop.
Save C4Code/3fb4e036986f34974d78 to your computer and use it in GitHub Desktop.
How to grab and save an image from a default UIButton
override func viewDidLoad() {
let fileName = "infoLight.png"
let b = UIButton.buttonWithType(UIButtonType.InfoLight) as! UIButton
let img = b.imageForState(.Normal)
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let dir = (paths[0] as! String)+"/"+fileName
UIImagePNGRepresentation(img).writeToFile(dir, atomically: true)
println(dir)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment