ios开发记录

iOS 四周半透明中间圆形全透明View制作

2019-07-25  本文已影响0人  selice

转载自原文: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];

}

上一篇 下一篇

猜你喜欢

热点阅读