Created
December 3, 2018 07:07
-
-
Save XcqRomance/c1f55163cffa1f32a147088de459277d to your computer and use it in GitHub Desktop.
1、绘制UIImage的圆角,并且不出现离屏渲染; 2、获取启动图片
This file contains 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
@implementation UIImage (CornerRadius) | |
- (UIImage*)cornerWithRadius:(CGFloat)radius andSize:(CGSize)size{ | |
CGRect rect = CGRectMake(0, 0, size.width, size.height); | |
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale); | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(radius, radius)]; | |
CGContextAddPath(ctx,path.CGPath); | |
CGContextClip(ctx); | |
[self drawInRect:rect]; | |
CGContextDrawPath(ctx, kCGPathFillStroke); | |
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return newImage; | |
} | |
+ (UIImage *)getTheLaunchImage { | |
CGSize viewSize = [UIScreen mainScreen].bounds.size; | |
NSString *viewOrientation = nil; | |
if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown) || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)) { | |
viewOrientation = @"Portrait"; | |
} else { | |
viewOrientation = @"Landscape"; | |
} | |
NSString *launchImage = nil; | |
NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"]; | |
for (NSDictionary* dict in imagesDict) | |
{ | |
CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]); | |
if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) | |
{ | |
launchImage = dict[@"UILaunchImageName"]; | |
} | |
} | |
return [UIImage imageNamed:launchImage]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment