@interface CcorView ()
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@property (nonatomic, strong) UIBezierPath *maskPath;
@property (nonatomic, strong) CAShapeLayer *maskLayer;
@property (nonatomic, strong) CAShapeLayer *maskLayer2;
@end
@implementation CcorView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame: frame];
if(self) {
[self setupUI];
}
return self;
}
- (void)setupUI {
self.gradientLayer = [CAGradientLayer new];
self.gradientLayer.startPoint = CGPointMake(0, 0.5);
self.gradientLayer.endPoint = CGPointMake(1, 0.5);
self.gradientLayer.frame = self.bounds;
self.maskLayer = [[CAShapeLayer alloc] init];
self.maskLayer.frame = self.bounds;
UIRectCorner corner = UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight;
self.gradientLayer.colors = @[(__bridge id)HB_RGBACOLOR(205, 200, 218, 1).CGColor, (__bridge id)HB_RGBACOLOR(255, 240, 218, 0).CGColor];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(12, 12)];
self.maskLayer.path = maskPath.CGPath;
self.gradientLayer.mask = self.maskLayer;
self.maskLayer2 = [[CAShapeLayer alloc] init];
self.maskLayer2.frame = self.bounds;
self.maskLayer2.path = maskPath.CGPath;
self.maskLayer2.lineWidth = 1;
self.maskLayer2.fillColor = UIColor.clearColor.CGColor;
self.maskLayer2.strokeColor = UIColor.blackColor.CGColor;
[self.layer addSublayer:self.gradientLayer];
[self.layer addSublayer:self.maskLayer2];
}
@end
iOS渐变色加3倒角加描边实现
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- OC 项目中遇到了折线图,使用了第三方库 Charts,Charts 是用 Swift 实现的,因此如果是 OC ...
- 转载自网友“tongyuling”原博客地址 http://www.cnblogs.com/tongyuling/...