转载自原文:https://blog.csdn.net/tabttoo/article/details/51262456
- (UIImage *)getImage{
UIGraphicsBeginImageContextWithOptions([UIScreen mainScreen].bounds.size, NO, 1.0);
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(con, [UIColor lightGrayColor].CGColor);//背景色
CGContextFillRect(con, [UIScreen mainScreen].bounds);
CGContextAddEllipseInRect(con, CGRectMake(50, 100, 200, 200));
CGContextSetBlendMode(con, kCGBlendModeClear);
CGContextFillPath(con);
UIImage *ima = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ima;
}
- (void)addImage{
UIImageView *imageV = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
imageV.image = [self getImage];
imageV.alpha = 0.5;
[self.view addSubview:imageV];
}
网友评论