通过cagradientLayer类封装uiimageview动画色度差
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, EcolorDirectionType)
{
EcolorDirectionUp, //上
EcolorDirectionDown, //下
EcolorDirectionRight, //右
EcolorDirectionLeft, //左
};
@interface ColorImageView : UIImageView /**
* @brief 确定方向
*/
@property(nonatomic,assign) EcolorDirectionType direction; /**
* @brief 颜色
*/
@property(nonatomic,strong) UIColor *color; /**
* @brief 百分比
*/
@property(nonatomic,assign) CGFloat percent; @end
#import "ColorImageView.h"
@interface ColorImageView ()
{
CAGradientLayer *_gradientLayer;
}
@end
@implementation ColorImageView
@synthesize color = _color;
@synthesize percent = _percent;
@synthesize direction = _direction; - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.frame = self.bounds;
_gradientLayer.borderWidth = 1.0f;
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)[UIColor redColor].CGColor
];
_gradientLayer.locations = @[@(0.1),@()]; [self.layer addSublayer:_gradientLayer];
}
return self;
}
/**
* @brief 设置颜色
* @param color 重写setter方法
*/
- (void)setColor:(UIColor *)color
{
_color = color;
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)color.CGColor
];
}
- (UIColor *)color
{
return _color;
}
/**
* @brief 设置颜色分割点
* @param percent 重写setter方法
*/
- (void)setPercent:(CGFloat)percent
{
_percent = percent;
_gradientLayer.locations= @[@(percent),@()];
} -(CGFloat)percent
{
return _percent;
} /**
* @brief 设置颜色渐变方向
* @param direction 重写setter方法
*/
-(void)setDirection:(EcolorDirectionType)direction
{
_direction=direction;
switch (direction) {
case EcolorDirectionUp:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
case EcolorDirectionDown:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, ); }
break;
case EcolorDirectionLeft:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, ); }
break;
case EcolorDirectionRight:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
default:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
}
}
-(EcolorDirectionType)direction
{
return _direction;
}
@end
#import "ViewController.h"
#import "ColorImageView.h"
@interface ViewController ()
{ ColorImageView *_imvColor;
}
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; _imvColor=[[ColorImageView alloc]initWithFrame:CGRectMake(, , , )];
_imvColor.image = [UIImage imageNamed:@""];
_imvColor.center = self.view.center; [self.view addSubview:_imvColor];
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(event) userInfo:nil repeats:YES];
// [self performSelector:@selector(event) withObject:nil afterDelay:2.0f]; }
- (void)event
{
_imvColor.direction=EcolorDirectionUp;
_imvColor.color=[UIColor cyanColor];
_imvColor.percent=arc4random()%/.f;
}
@end
通过cagradientLayer类封装uiimageview动画色度差的更多相关文章
- iOS常用动画 类封装
//这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...
- 原生Js封装的动画类
算法用的是Tween类,需要研究的参考这篇文章: http://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html 网页里常用的动画 放大 ...
- .Net Core ORM选择之路,哪个才适合你 通用查询类封装之Mongodb篇 Snowflake(雪花算法)的JavaScript实现 【开发记录】如何在B/S项目中使用中国天气的实时天气功能 【开发记录】微信小游戏开发入门——俄罗斯方块
.Net Core ORM选择之路,哪个才适合你 因为老板的一句话公司项目需要迁移到.Net Core ,但是以前同事用的ORM不支持.Net Core 开发过程也遇到了各种坑,插入条数多了也特别 ...
- salesforce 零基础学习(四十八)自定义列表分页之Pagination基类封装 ※※※
我们知道,salesforce中系统标准列表页面提供了相应的分页功能,如果要使用其分页功能,可以访问http://www.cnblogs.com/zero-zyq/p/5343287.html查看相关 ...
- 原生JS封装简单动画效果
原生JS封装简单动画效果 一致使用各种插件,有时候对原生JS陌生了起来,所以决定封装一个简单动画效果,熟悉JS原生代码 function animate(obj, target,num){ if(ob ...
- 在Android中动画移动一个View的位置,采用Scroller类实现Android动画之 View移动
在Android中动画移动一个View的位置,采用Scroller类实现 今天说最近自己遇到的一个问题,就是要用动画效果来移动一个VIew的位置. 这个具体的情况是,需要做一个SlidingMenu的 ...
- Redis操作Set工具类封装,Java Redis Set命令封装
Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...
- Redis操作List工具类封装,Java Redis List命令封装
Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...
- Redis操作Hash工具类封装,Redis工具类封装
Redis操作Hash工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>> ...
随机推荐
- MYSQL数据库性能调优之八:mysql日志
MySQL日志 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志.中继日志: 使用 SHOW GLOBAL VARIABLES LIKE '%log%'; 查询所有日志配置详情: 一. ...
- vs常用插件之javsscript插件
1.JSEnhancements 折叠JS和CSS代码 http://visualstudiogallery.msdn.microsoft.com/0696ad60-1c68-4b2a-9646-4b ...
- Working with nil
[Working with nil] It’s always a good idea to initialize scalar variables at the time you declare th ...
- C++11初始化列表
[C++11之初始化列表] 在C++03中,在严格遵守POD的定义和限制条件的结构及类型上可以使用初始化列表(initializer list),构想是结构或是数组能够依据成员在该结构内定义的顺序通过 ...
- CSS画出的各种形状图
利用CSS可以画出各种需要的图形目录[1]矩形[2]圆形[3]椭圆[4]直角三角形[5]正三角形[6]平行四边形[7]梯形[8]六角星[9]六边形[10]五角星简单图形 矩形div{ width: 1 ...
- 代码中设置excel自定义格式为[红色]的处理方法
有时候,excel的自定义格式设置时 ,会遇到需要设置为¥#,##0;[红色]¥-#,##0的格式. 其中会带一个颜色标记,但是如果这样的一句代码,放在英文版的Office里面,就失效了,因为英文版应 ...
- ssh 框架整合试例 (spring+struts2+hibernate)
1.首先用Eclipse创建一个web项目(Eclipse EE 版) new->Other-> 输入web 然后选择Dynamic Web Project->next-> 输 ...
- Oracle数据库编程:使用PL/SQL编写触发器
8.使用PL/SQL编写触发器: 触发器存放在数据缓冲区中. 触发器加序列能够实现自动增长. 在触发器中不能使用connit和rollback. DML触发器 ...
- kafka分布式消息队列 — 基本概念介绍
[http://www.inter12.org/archives/818] 这个应该算是之前比较火热的词了,一直没时间抽出来看看.一个新东西出来,肯定是为了解决某些问题,不然不会有它的市场.先简单看下 ...
- 系列文章--SharePoint 开发教程
SharePoint 2013 图文开发系列之入门教程 学习地址:http://www.cnblogs.com/jianyus/p/3461719.html 里面有2007.2010.2013各个版本 ...