#import <UIKit/UIKit.h>

@interface ProgressView : UIView
@property(nonatomic,assign)CGFloat progress;
@property(nonatomic,strong)UIColor *layColor;
@end
#import "ProgressView.h"
@interface ProgressView ()
{
CALayer *progressLayer; CGFloat currentViewWidth;//当前view的宽度
}
@end
@implementation ProgressView
@synthesize progress=_progress;
@synthesize layColor=_layColor; - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
progressLayer=[CALayer layer];
progressLayer.frame=CGRectMake(, , , frame.size.height);
progressLayer.backgroundColor=[UIColor redColor].CGColor;
[self.layer addSublayer:progressLayer];
currentViewWidth=frame.size.width;
}
return self;
}
-(void)setProgress:(CGFloat)progress
{
_progress=progress;
if (progress<=) {
progressLayer.frame=CGRectMake(, , , self.frame.size.height);
}
else if (progress<=)
{
progressLayer.frame=CGRectMake(, , progress*currentViewWidth, self.frame.size.height);
}
else
{
progressLayer.frame=CGRectMake(, , currentViewWidth, self.frame.size.height);
} }
-(CGFloat)progress
{
return _progress;
}
-(void)setLayColor:(UIColor *)layColor
{
_layColor=layColor;
self.layer.backgroundColor=layColor.CGColor;
}
-(UIColor *)layColor
{
return _layColor;
}
@end
#import "ViewController.h"
#import "ProgressView.h"
@interface ViewController ()
@property(nonatomic,strong)ProgressView *progressView;
@property(nonatomic,strong)NSTimer *timer;
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.progressView=[[ProgressView alloc]initWithFrame:CGRectMake(, , , )];
[self.view addSubview:self.progressView];
_timer=[NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(layerAnimation) userInfo:nil repeats:YES]; }
-(void)layerAnimation
{
self.progressView.progress=arc4random()%/100.0f;
self.progressView.layColor=[UIColor greenColor];
} @end

最新文章

  1. Webkit 文字和背景效果
  2. chrome 问题
  3. Kotlin语法(类和对象)
  4. fastx_toolkit去除测序数据中的接头和低质量的reads
  5. Web GIS 离线地图
  6. 活动 Activity 四种加载模式
  7. PYTHON 获取机器硬件信息及状态
  8. Collections.unmodifiableList()的使用与场景
  9. MD5加密。
  10. maven依赖冲突
  11. liunx 安装redis 4.0
  12. 【HNOI 2018】道路
  13. git出现warning: LF will be replaced by CRLF的解决方法
  14. ES6中对象
  15. 对象生命周期中至少被GC一次后存活
  16. ext.js的目录结构的简单解释
  17. MyBatis关联查询,一对多关联查询
  18. Web API 源码剖析之全局配置
  19. Linux(Red hat)无网离线安装TensorFlow
  20. 【转发】jQuery1.9.1至最高版本针对checkbox的调整

热门文章

  1. css斜线
  2. JSF 2 panelGrid example
  3. C#读取文件为byte数组
  4. mysql编码详解
  5. CCF 201312-2 ISBN号码 (水题)
  6. angular实践第一弹:选项卡开发
  7. Windows 10 Edge浏览器、照片查看程序关闭“平滑滚动”
  8. css 精灵的用法
  9. extjs表格下的分页条——Ext.grid.Panel 的 pagingtoolbar
  10. JSP页面上用横线代替文本框