Created
November 8, 2024 07:49
-
-
Save hanfengs/ae939b6cd860530eee8ffadb74aea009 to your computer and use it in GitHub Desktop.
[2 次拉伸图片]
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
/// 通过 2 次拉伸图片达到效果,聊天气泡,尖尖在气泡中间 | |
- (UIImage *)returnImageStretchLeftAndRightWith:(CGSize)size { | |
UIImage *originalImage = UIImageMake(@"course_module_tab_bg"); | |
CGSize imageSize = originalImage.size; | |
CGSize bgSize = size; | |
UIEdgeInsets leftInsets = UIEdgeInsetsMake(0, imageSize.height/2, 0, imageSize.width/2 + 5); | |
UIImage *tempImage = [originalImage resizableImageWithCapInsets:leftInsets resizingMode:UIImageResizingModeStretch]; | |
CGFloat tempWidth = (bgSize.width)/2 + imageSize.width/2; | |
UIGraphicsBeginImageContextWithOptions(CGSizeMake(tempWidth, imageSize.height), NO, [UIScreen mainScreen].scale); | |
[tempImage drawInRect:CGRectMake(0, 0, tempWidth, bgSize.height)]; | |
UIImage *firstStrechImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
UIEdgeInsets rightInsets = UIEdgeInsetsMake(0, (bgSize.width)/2 + 5, 0, imageSize.height/2); | |
UIImage *rightStretchedImage = [firstStrechImage resizableImageWithCapInsets:rightInsets resizingMode:UIImageResizingModeStretch]; | |
return rightStretchedImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment