Skip to content

Instantly share code, notes, and snippets.

@donpark
Created January 11, 2015 06:53
Show Gist options
  • Save donpark/7549a1a2a5f7eef7fbea to your computer and use it in GitHub Desktop.
Save donpark/7549a1a2a5f7eef7fbea to your computer and use it in GitHub Desktop.
CALayer with resizable image
- (CALayer*)layerFromResiableImage:(UIImage*)image {
CGSize size = [image size];
UIEdgeInsets insets = [image capInsets];
CALayer *layer = [CALayer layer];
[layer setContents:(id)[image CGImage]];
layer.contentsCenter = CGRectMake(insets.left / size.width, insets.top / size.height,
1.0/size.width, 1.0 / size.height);
return layer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment