// 添加圆角
self.layer.cornerRadius = 15.0f;
[self.layer setMasksToBounds:YES];
// 添加渐变
UIView *topShadowView = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.origin.x+kLeftPadding,
self.bounds.origin.y + self.bounds.size.height - kShadowHeight
,self.bounds.size.width-kLeftPadding - kRightPadding , kShadowHeight)];
CAGradientLayer *topShadow = [CAGradientLayer layer];
topShadow.frame = CGRectMake(0, 0, topShadowView.bounds.size.width, kShadowHeight);
topShadow.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor clearColor] CGColor], nil];
[topShadowView.layer insertSublayer:topShadow atIndex:0];
[self addSubview:topShadowView];
本文介绍如何使用Swift为iOS应用中的视图添加圆角效果及顶部渐变阴影,涉及CAGradientLayer和UIView的layer属性设置。
901

被折叠的 条评论
为什么被折叠?



