Skip to content

Instantly share code, notes, and snippets.

@brandhill
Created July 29, 2017 07:15
Show Gist options
  • Save brandhill/320b8a85b3eac607e3d8eda184427158 to your computer and use it in GitHub Desktop.
Save brandhill/320b8a85b3eac607e3d8eda184427158 to your computer and use it in GitHub Desktop.
Equivalent Android 9-patch for iOS and Swift 3.0 (multiple stretchable areas)
// origin
UIImageView *unHandleImg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREENWIDTH-200)/2, 100, 200, 30)];
unHandleImg.image = [UIImage imageNamed:@"theImage"];
[self.view addSubview:unHandleImg];
// with stretchable
UIImageView *handleImg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREENWIDTH-200)/2, 200, 200, 30)];
UIImage *img = [UIImage imageNamed:@"theImage"];
// stretchable areas
img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(35, 35, 35, 35) resizingMode:UIImageResizingModeStretch];
handleImg.image = img;
[self.view addSubview:handleImg];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment