Last active
October 1, 2017 02:33
-
-
Save PhilCai1993/c9d63e9e40b166d1a64f to your computer and use it in GitHub Desktop.
CALayer and [UIImage resizableImageWithCapInsets:resizingMode]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static CGRect CGRectCenterRectForResizableImage(UIImage* image) { | |
return CGRectMake(image.capInsets.left / image.size.width, | |
image.capInsets.top / image.size.height, | |
(image.size.width - image.capInsets.right - image.capInsets.left) / image.size.width, | |
(image.size.height - image.capInsets.bottom - image.capInsets.top) / image.size.height); | |
} | |
... | |
CALayer *layer = [CALayer layer]; | |
UIImage *originImage = [UIImage imageNamed:@"shopping_bg_reply"]; | |
UIEdgeInsets imageInset = UIEdgeInsetsMake(10, 22, 23, 8); | |
UIImage *resource = [originImage resizableImageWithCapInsets:imageInset | |
resizingMode:UIImageResizingModeStretch]; | |
self.contentsCenter = CGRectCenterRectForResizableImage(self.resourceImage); | |
self.contentsScale = [UIScreen mainScreen].scale; | |
self.contents = (id)self.resource.CGImage; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment