IOS UIView圆角,阴影,边框,渐增光泽

圆角

sampleView.layer.cornerRadius = 2.5; // 圓角的弧度
sampleView.layer.masksToBounds = YES;

阴影

sampleView.layer.shadowColor = [[UIColor blackColor] CGColor];
sampleView.layer.shadowOffset = CGSizeMake(3.0f, 3.0f); // [水平偏移, 垂直偏移]
sampleView.layer.shadowOpacity = 0.5f; // 0.0 ~ 1.0 的值
sampleView.layer.shadowRadius = 10.0f; // 陰影發散的程度

边框

sampleView.layer.borderWidth = 1;
sampleView.layer.borderColor = [[UIColor blackColor] CGColor];


渐增光泽

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = sampleView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor grayColor] CGColor], nil]; // 由上到下的漸層顏色
[sampleView.layer insertSublayer:gradient atIndex:0];