宽容他人,放过自己。

图片指定的角为圆角

Posted on By anchoriteFili

iOS开发之指定UIView的某几个角为圆角

752372-20151008192015518-1815711683.png

#pragma mark 直接创建view,然后对view边角进行处理
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 400, 80, 80)];
    view2.backgroundColor = [UIColor redColor];
    [self.view addSubview:view2];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view2.bounds;
    maskLayer.path = maskPath.CGPath;
    view2.layer.mask = maskLayer;
    
#pragma mark imageView圆边设置
    UIImageView *whiteBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 200, 200)];
    whiteBackImageView.image = [UIImage imageNamed:@"cell背景白图"];
    [self.view addSubview:whiteBackImageView];
    
    UIBezierPath *whiteBackImageViewPath = [UIBezierPath bezierPathWithRoundedRect:whiteBackImageView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
    CAShapeLayer *whiteBackImageViewLayer = [[CAShapeLayer alloc] init];
    whiteBackImageViewLayer.frame = whiteBackImageView.bounds;
    whiteBackImageViewLayer.path = whiteBackImageViewPath.CGPath;
    whiteBackImageView.layer.mask = whiteBackImageViewLayer;