设置半圆角和阴影方法:byRoundingCorners:[ 要设置半圆角的方位],下方例子是左上角,右上角
let maskPath =UIBezierPath.init(roundedRect: chageBtn.bounds, byRoundingCorners: [UIRectCorner.topLeft ,UIRectCorner.topRight], cornerRadii:CGSize.init(width:5, height:5))
let maskLayer =CAShapeLayer()
maskLayer.path = maskPath.cgPath
button.layer.mask = maskLayer // 设置Button边角
给视图设置阴影
view.shadowColor = [[UIColorblackColor] CGColor]; // 阴影颜色
view.layer.shadowOpacity = 0.5; // 不透明度
view.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
注意:
设置圆角后又设置阴影是无效果的,可以尝试在视图上再添加一层layer,在新添加的layer上设置阴影效果