var contentImageView: UIImageView!{
didSet{
contentImageView.image!.resizableImageWithCapInsets(UIEdgeInsets(top: 5,left: 5,bottom: 5,right: 5))
}
}
You can use the method
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode;
capInsets
is a specific area(e.g. UIEdgeInsetsMake(10, 18, 10, 18)
), resizingMode
should select UIImageResizingModeStretch
.
UIImage *image = [[UIImage imageNamed:@"bubble.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 18, 10, 18) resizingMode:UIImageResizingModeStretch];
bubbleImageView.image = image;
There is a sleek option in Xcode .xcassets. You can select the images and slice it from there so that it's strechable in specific parts only below are the images please explore this option.
Borrowed Bhavin's Image for demonstration :D