Your Site Title

UView Layer

设置圆角

// 四个角
view.layer.cornerRadius = 15;
view.layer.masksToBounds = YES; // 全部裁剪(包括子view, 包括当前view的阴影)

// 设置指定角
if (@available(iOS 11.0, *)) {
    _taskCardTopV.layer.cornerRadius = 10;
    _taskCardTopV.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;   } else {
    UIBezierPath *pathTaskCardTopV = [UIBezierPath bezierPathWithRoundedRect:_taskCardTopV.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerTopLeft) cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *layerTaskCardTopV = [[CAShapeLayer alloc]init];
    layerTaskCardTopV.frame = _taskCardTopV.bounds;
    layerTaskCardTopV.path = pathTaskCardTopV.CGPath;
    _taskCardTopV.layer.mask = layerTaskCardTopV;   }

设置阴影

view.layer.shadowColor = C_THEME_2.CGColor;
view.layer.shadowOffset = CGSizeMake(1, 1);
view.layer.shadowOpacity = 0.3;
view.layer.shadowRadius = 10;
view.layer.shadowPath =  [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
view.layer.shouldRasterize = true;

如果view设置了masksToBounds, 那么阴影会被剪裁, 设置无效. 解决方法, 主view和子view都自己设置圆角, 并且masksToBounds设置成NO

Reference