将CAGradientLayer当做mask使用
2016-02-16 21:03
183 查看
将CAGradientLayer当做mask使用
效果
源码
https://github.com/YouXianMing/Animations
细节
效果
源码
https://github.com/YouXianMing/Animations
// // CAGradientView.h // MaskView // // Created by YouXianMing on 16/2/15. // Copyright © 2016年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> @interface CAGradientView : UIView /** * CAGradientLayer's colors. */ @property (nonatomic, strong) NSArray *colors; /** * CAGradientLayer's locations. */ @property (nonatomic, strong) NSArray *locations; /** * CAGradientLayer's startPoint. */ @property (nonatomic) CGPoint startPoint; /** * CAGradientLayer's endPoint. */ @property (nonatomic) CGPoint endPoint; @end
// // CAGradientView.m // MaskView // // Created by YouXianMing on 16/2/15. // Copyright © 2016年 YouXianMing. All rights reserved. // #import "CAGradientView.h" @interface CAGradientView () { CAGradientLayer *_gradientLayer; } @end @implementation CAGradientView + (Class)layerClass { return [CAGradientLayer class]; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _gradientLayer = (CAGradientLayer *)self.layer; } return self; } #pragma mark - 重写setter,getter方法 @synthesize colors = _colors; - (void)setColors:(NSArray *)colors { _colors = colors; // 将color转换成CGColor NSMutableArray *cgColors = [NSMutableArray array]; for (UIColor *tmp in colors) { id cgColor = (__bridge id)tmp.CGColor; [cgColors addObject:cgColor]; } // 设置Colors _gradientLayer.colors = cgColors; } - (NSArray *)colors { return _colors; } @synthesize locations = _locations; - (void)setLocations:(NSArray *)locations { _locations = locations; _gradientLayer.locations = _locations; } - (NSArray *)locations { return _locations; } @synthesize startPoint = _startPoint; - (void)setStartPoint:(CGPoint)startPoint { _startPoint = startPoint; _gradientLayer.startPoint = startPoint; } - (CGPoint)startPoint { return _startPoint; } @synthesize endPoint = _endPoint; - (void)setEndPoint:(CGPoint)endPoint { _endPoint = endPoint; _gradientLayer.endPoint = endPoint; } - (CGPoint)endPoint { return _endPoint; } @end
细节
相关文章推荐
- GDKOI模拟 Manufactoria
- 你只是看起来很努力
- libcurl库进行http通讯-开篇
- libcurl库进行http通讯-开篇
- Tcl -- eval
- 8大Android调试工具
- HTTP 请求方式: GET和POST的比较
- CSDN 博客积分 如何获取
- MessageBox语法介绍
- 迭代式开发技术
- [整理][LaTex]小技巧之——首行缩进
- 20160203.CCPP体系详解(0013天)
- (转)JAVA中堆和栈的区别
- GPU编程与CG语言
- 【走过的弯路】 IC工作温度的理解
- CSS3の新特性
- ssh(struts2.3.8+spring3.2+heibernate4.1+annotation零配置
- 偷懒了一天,去给人装系统去了~ 今天继续更 自己敲代码实现下拉刷新上滑加载更多
- bnuoj 51275(道路修建-并查集按秩合并)
- 并发编程复习笔记