1、在DrawCircle.h文件中

  提供了接口,在使用的时候,可以设定圆心、半径、角度、圆环的宽度、圆环的背景底色、圆环的进度条颜色,当然后面三个有自定义的值。

//

//  DrawCircle.h

//  Demo-draw

//

//  Created by yyt on 16/5/10.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface DrawCircle : UIView

@property(nonatomic,assign) CGPoint centerPoint;

@property(nonatomic,assign) CGFloat radius;

@property(nonatomic,assign) CGFloat angleValue;  //圆环进度占有的角度,0~360

@property(nonatomic,assign) CGFloat lineWidth;

@property(nonatomic,strong) UIColor *bgLineColor;

@property(nonatomic,strong) UIColor *lineColor;

@end

2、在DrawCircle.m文件中

//

//  DrawCircle.m

//  Demo-draw

//

//  Created by yyt on 16/5/10.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import "DrawCircle.h"

@implementation DrawCircle

- (instancetype)initWithFrame:(CGRect)frame {

self = [super initWithFrame:frame];

self.backgroundColor = [UIColor whiteColor];

self.lineWidth = 10;

self.bgLineColor = [UIColor lightGrayColor];

self.lineColor = [UIColor orangeColor];

return self;

}

- (void)drawRect:(CGRect)rect {

CGContextRef bgContextRef = UIGraphicsGetCurrentContext();

CGContextAddArc(bgContextRef, _centerPoint.x, _centerPoint.y, _radius, 0, 10, 0);

CGContextSetLineWidth(bgContextRef, _lineWidth);

[_bgLineColor setStroke];

CGContextStrokePath(bgContextRef);

CGContextRef contextRef = UIGraphicsGetCurrentContext();

CGContextAddArc(contextRef, _centerPoint.x, _centerPoint.y, _radius, M_PI/2, M_PI/2+_angleValue/180*M_PI, 0);

CGContextSetLineWidth(contextRef, _lineWidth);

[_lineColor setStroke];

CGContextStrokePath(contextRef);

}

@end

3、在需要使用圆环进度条的地方ViewController.m文件中

//

//  ViewController.m

//  Demo-draw

//

//  Created by yyt on 16/5/10.

//  Copyright © 2016年 yyt. All rights reserved.

//

#import "ViewController.h"

#import "DrawCircle.h"

@interface ViewController ()

@property(nonatomic,strong) DrawCircle *view2;

@end

@implementation ViewController

static int hehe = 30;

- (void)viewDidLoad {

[super viewDidLoad];

DrawCircle *view2 = [[DrawCircle alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];

self.view2 = view2;

view2.centerPoint = CGPointMake(50, 50);

view2.radius = 30;

view2.angleValue = hehe;

view2.lineWidth = 20;

view2.lineColor = [UIColor orangeColor];

[self.view addSubview:view2];

  //进度+

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

button.frame = CGRectMake(100, 100, 100, 30);

button.backgroundColor = [UIColor blueColor];

[button addTarget:self action:@selector(hehe) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

  //进度-

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];

button2.frame = CGRectMake(100, 150, 100, 30);

button2.backgroundColor = [UIColor redColor];

[button2 addTarget:self action:@selector(hehe2) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button2];

}

- (void)hehe {

hehe += 30;

self.view2.angleValue = hehe;

[self.view2 setNeedsDisplay];

}

- (void)hehe2 {

hehe -= 30;

self.view2.angleValue = hehe;

[self.view2 setNeedsDisplay];

}

@end

iOS开发——自定义进度圆环的更多相关文章

  1. iOS开发自定义字体之静态字体

    最后更新 2017-04-25 在iOS开发中经常会用到字体, 一般字体文件比较小的,单一的,几十k, 可以通过内置进去;如果字体文件比较多或者字体文件比较大,通常通过动态加载方式. 静态加载方式 将 ...

  2. iOS 开发自定义一个提示框

    在开发的时候,会碰到很多需要提示的地方,提示的方法也有很多种,ios 8 以前的版本有alertview还是以后用的alertController,都是这种作用, 但是不够灵活,而且用的多了,用户体验 ...

  3. [IOS 开发] 自定义(重写) UITableViewCell的高亮背景色

    IOS的sdk中,对UITableViewCell的高亮背景色只支持两种颜色,分别为UITableViewCellSelectionStyleBlue和UITableViewCellSelection ...

  4. iOS开发-自定义UIAlterView(iOS 7)

    App中不可能少了弹框,弹框是交互的必要形式,使用起来也非常简单,不过最近需要自定义一个弹框,虽然iOS本身的弹框已经能满足大部分的需求,但是不可避免还是需要做一些自定义的工作.iOS7之前是可以自定 ...

  5. IOS开发自定义CheckBox控件

    IOS本身没有系统的CheckBox组件,但是实际开发中会经常用到,所以专门写了一个CheckBox控件,直接上代码 效果图: UICheckBoxButton.h文件如下: #import #imp ...

  6. iOS开发自定义转场动画

    1.转场动画 iOS7之后开发者可以自定义界面切换的转场动画,就是在模态弹出(present.dismiss),Navigation的(push.pop),TabBar的系统切换效果之外自定义切换动画 ...

  7. IOS开发自定义tableviewcell的注意点😄

    自定义tableviewcell 1.xib,nib拖控件:awakefromnib: 设置2,不拖控件:- (instancetype)initWithStyle:(UITableViewCellS ...

  8. iOS开发自定义流水布局

    //集成UICollectionViewFlowLayout 自己写的布局 //  SJBFlowLayout.m //  自定义流水布局 // //  Created by zyyt on 16/7 ...

  9. iOS开发 自定义UIAlertController的样式

    引言: 关于提示框, 系统自带的提示框有时可能满足不了我们的需求, 比如一个提示框的取消按钮我需要灰色字体显示, 这时候就需要自定义提示框的样式了. 示例图 苹果自iOS8开始,就已经废弃了之前用于界 ...

随机推荐

  1. Monad / Functor / Applicative 浅析

    前言 Swift 其实比 Objective-C 复杂很多,相对于出生于上世纪 80 年代的 Objective-C 来说,Swift 融入了大量新特性.这也使得我们学习掌握这门语言变得相对来说更加困 ...

  2. public <T> void method(T var)

    今天项目中遇到这样一个方法: public <T> void method(T var) 不太明白什么意思,后来搜索下几篇文章,自己总结一下,和大家分享. 先看例子: 1.static v ...

  3. RatingBar

    题记:保持旺盛的求知欲.希望会一直这样. 说明:来了新控件了.就是经常用的打分的那种东东. 说明:1.看上图分别是系统自带的和自己做的.rating就是设置小星星的数目. 2.用系统自带的必须是Wra ...

  4. vim的vimrc设置

    map <F9> :call SaveInputData()<CR> func! SaveInputData() exec "tabnew" exec 'n ...

  5. JS-DOM元素灵活查找

    用className选择元素 封装成函数 <title>无标题文档</title> <script> /* window.onload=function () { ...

  6. JS定时器的使用--延时提示框

    <title>无标题文档</title> <style> div{float:left;margin:10px;} #div1{width:50px; height ...

  7. 学习笔记——策略模式Strategy

    策略模式,与模板模式一样,都是为了将接口和算法实现解耦,但策略模式更主要是整体算法的替换,而模板模式主要是流程一致,部分算法的替换. 个人理解为,一般算法替换,使用策略模式,当算法流程一致,可以提取为 ...

  8. Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? \Android Studio快捷键之代码提示

    问:Android Studio中有没有类似于Eclipse中的ctrl+2+L的快捷键? 答:有,as中的快捷键是Ctrl+Alt+V AndroidStudio和Eclipse常用快捷键对比 功能 ...

  9. CSS样式覆盖规则

    有一下问题, 想让下面的border生效 ,#比. 优先级高, #navigator { height: 100%; width: 200; position: absolute; left: 0; ...

  10. navicat 导出mysql表结构

    选中需要导出表结构的数据库,右键,在显示的菜单中选择“数据传输”这一项 ,在弹出窗口中“数据传输”单击选择“高级”一项,在“高级”中把“记录选项”中的勾去掉,在做一些设置,最后导出表数据就不会导出记录 ...