美文网首页
iOS 图片裁减 中间高亮区域处理

iOS 图片裁减 中间高亮区域处理

作者: 114105lijia | 来源:发表于2019-11-19 15:05 被阅读0次

我们在裁减照片时,中间可能要高亮,四周是灰色半透明蒙层,可以如下设置:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImage *image = [UIImage imageNamed:@"WechatIMG21"];
    [self.view.layer setContents:(id)image.CGImage];
    
    //先遮挡全部
    UIView *holeView = [[UIView alloc] initWithFrame:self.view.bounds];
    holeView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.view addSubview:holeView];

    CAShapeLayer *layer = [CAShapeLayer layer];
    //高亮区域
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 250, 200, 200)];
    //后面的一个path 为背景path'
    [path appendPath:[UIBezierPath bezierPathWithRect:self.view.bounds]];
    layer.path = path.CGPath;
    //最主要的就是这个模式。fillRule有两种种模式
    layer.fillRule = kCAFillRuleEvenOdd;
    
    [holeView.layer setMask:layer];
}

效果如下:


image.png

相关文章

网友评论

      本文标题:iOS 图片裁减 中间高亮区域处理

      本文链接:https://www.haomeiwen.com/subject/tpnwictx.html