Skip to content

Instantly share code, notes, and snippets.

@programmingthomas
Created November 7, 2013 20:27
Show Gist options
  • Save programmingthomas/7361314 to your computer and use it in GitHub Desktop.
Save programmingthomas/7361314 to your computer and use it in GitHub Desktop.
Using nine patch/sliced images
//Using with an image view
imageView.image = [UIImage imageNamed:@"myimage"];
//Using as the background to another view
//Note that you will need to redraw the background when resizing
//Therefore if you need to animate resizes it may be more sensible to add a UIImageView
//as the background to your view
UIImage * myImage = [UIImage imageNamed:@"myimage"];
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, NO, 0);
[myImage drawInRect:myView.bounds];
UIImage * backgroundImage = UIGraphicsGetImageFromCurrentContext();
UIGraphicsEndImageContext();
myView.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment