#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

通过改变uiview的layer的frame来实现进度条的更多相关文章

  1. IOS 杂笔-11(实现在外部无法改变UIView的size)

    我想题目说的或许不是很清楚,那么现在我详细介绍一下这篇随笔内容. 在外部无法改变UIVIew控件的size. 这里说是UIView,但是事实上,是大多数控件而绝非仅UIView. 想要实现在外部无法改 ...

  2. UIView和layer的关系

    UIView和layer的关系 UIView是layer的代理 View的根layer ---也就是说view本身自带一个layer, 这个layer 我们叫它根layer 所有视图显示是因为继承UI ...

  3. UIView和layer的区别

    每个 UIView 内部都有一个 CALayer 在背后提供内容的绘制和显示,并且 UIView 的尺寸样式都由内部的 Layer 所提供.两者都有树状层级结构,layer 内部有 SubLayers ...

  4. iOS开发笔记-根据frame大小动态调整fontSize的自适应文本及圆形进度条控件的实现

    最近同样是新App,设计稿里出现一种圆形进度条的设计,如下: 想了想,圆形进度条实现起来不难,但是其中显示百分比的文本确需要自适应,虽然可以使用时自己设定文本字体的大小,但是这样显得很麻烦,也很low ...

  5. Android课程---用进度条改变图片透明度

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  6. layer.msg 添加在Ajax之前 显示进度条。

    一.使用方法:1)必须先引入jQuery1.8或以上版本 <script src="jQuery的路径"></script> <script src= ...

  7. 改变UIView 的位置 Center和Frame

    网上找了一个,一般来说 有两种方法: 1.改变view 的Frame [cell setFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#> ...

  8. UIView 中bounds和frame的差别

    搞iOS开发的童鞋基本都会用过UIView,那他的bounds和frame两个属性也不会陌生,那这两个有什么实质性的区别呢? 先看到下面的代码你肯定就明白了一些: -(CGRect)frame{    ...

  9. swift为UIView添加extension扩展frame

    添加swift file:UIView+Extension import UIKit extension UIView { // x var x : CGFloat { get { return fr ...

随机推荐

  1. C++ 16进制转10进制

    #include <stdio.h>#include <string.h>unsigned long f(char* str){ unsigned long var=0; un ...

  2. CSU1612Destroy Tunnels(强连通)

    Destroy Tunnels 原来早忘记了离散里含有这么一个叫传递闭包的东西 矩阵A的闭包B = A U A^2 U A^3 U ... 所以这里直接如果A[i][j]!= 0,建边i->j跑 ...

  3. java复制File文件操作

    ==========================复制File操作========================= /**  *   * @param newPath要赋值的路径  * @para ...

  4. mysql max_allowed_packet错误

    mysql错误 max_allowed_packet 查看目前配置 show VARIABLES like '%max_allowed_packet%'; 修改: set global max_all ...

  5. 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]

    3.2 Create创建用户 [HttpPost, Authorize] public async Task<ActionResult> Create( [Bind(Include = & ...

  6. [转]在Arcmap中加载互联网地图资源的4种方法

    转自http://blog.3snews.net/space.php?uid=6955280&do=blog&id=67981 前一段时间想在Arcmap中打开互联网地图中的地图数据, ...

  7. 【ToolGood.Words】之【StringSearch】字符串搜索——基于BFS算法

    字符串搜索中,BFS算法很巧妙,个人认为BFS算法效率是最高的. [StringSearch]就是根据BFS算法并优化. 使用方法: string s = "中国|国人|zg人|fuck|a ...

  8. 【转载】Fragment 全解析(1):那些年踩过的坑

    http://www.jianshu.com/p/d9143a92ad94 Fragment系列文章:1.Fragment全解析系列(一):那些年踩过的坑2.Fragment全解析系列(二):正确的使 ...

  9. maven中解决javax.servlet.jsp.PageContext cannot be resolved to a type

    在eclipse环境下用maven出现:javax.servlet.jsp.PageContext cannot be resolved to a type. 这是由于没有引入jsp-api引发的问题 ...

  10. Codeforces Round #308 (Div. 2) A. Vanya and Table 暴力

    A. Vanya and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...