圆形倒计时
来源:互联网 发布:藤井莉娜淘宝 编辑:程序博客网 时间:2024/05/16 09:02
圆形倒计时,自定义UIView ,使用UIView自带的drawRect:(CGRect)方法,动态绘图
@interface CXRoundView :UIView
@property (nonatomic,strong)NSTimer *circleTimer;
@property (nonatomic,assign)NSInteger timeCount;
@end
#import "CXRoundView.h"
#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height
@implementation CXRoundView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
self.backgroundColor = [UIColorwhiteColor];
[selfrunningTimer];
}
return self;
}
- (void)runningTimer{
self.circleTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
}
- (void)timerAction:(NSTimer *)timer{
static NSInteger timeCount =600;
timeCount--;
self.timeCount = timeCount;
if (self.timeCount ==0) {
[self.circleTimer invalidate];
self.circleTimer =nil;
[self finishView];
}
[self setNeedsDisplay];
}
- (void)finishView{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提醒"message:@"倒计时结束"delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
[self removeFromSuperview];
}
- (void)drawRect:(CGRect)rect {
//获取上下文对象
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context,3);
CGContextSetRGBStrokeColor(context,1.0,69 / 255.0,0.5,1.0);
//CGContextAddArc(上下文对象,圆心x,圆心y,曲线开始点,曲线结束点,半径)
CGContextAddArc(context,self.frame.size.width /2.0, self.frame.size.height / 2.0, self.bounds.size.width / 2.0 - 3.0,0,self.timeCount /600.0 *2 *M_PI,0);
CGContextStrokePath(context);
}
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
使用该自定义view时只需要引入头文件,创建CXRoundView对象,添加到控制器的view上即可
CXRoundView *circle = [[CXRoundView alloc]initWithFrame:CGRectMake(WIDTH - 72, HEIGHT /4 -100,50,50)];
[self.view addSubview:circle];
来源于 https://github.com/Easyzhan/CircleCountDown
- 圆形倒计时
- android 圆形倒计时实现
- android 自定义倒计时控件(圆形倒计时显示)
- 自定义圆形进度条 自定义倒计时进度条
- 自定义圆形进度条 自定义倒计时进度条
- Android模仿圆形圆圈倒计时实现
- 自定义圆形进度条,模拟开屏广告倒计时
- Android闪屏页圆形倒计时进度条实现
- 圆形头像和倒计时引导页按钮点击跳转
- Android 带小圆圈的倒计时圆形进度条
- 带动画效果的圆形进度条显示定时器倒计时
- 圆形
- 打造一个可分割的华丽圆形进度条,适合倒计时等场景
- Html5添加时尚的圆形进度条样式的倒计时插件教程
- DialogFragment实现带数字倒计时和小圆点进度的圆形进度条
- Android自定义View之带小圆圈的倒计时圆形进度条
- 自定义控件之仿启动页右上角的圆形跳过按钮倒计时功能
- 一款用于文件上传和下载倒计时功能的圆形进度条
- 机器学习算法疗程(HMM)
- IAR下stm32使用12M外部晶振
- php下intval()和(int)转换使用与区别
- Android Data Binding 系列(一) -- 详细介绍与使用
- Unity 3D - 光照计算中的diffuse的计算公式
- 圆形倒计时
- Skype和QQ语音有几个区别
- C语言笔记2--控制流
- Laravel错误与日志处理
- PHP Mysql 用PHP查看mysql数据库所有表名
- TCP/IP详解,卷1:协议,第二章链路层
- Letcode 1.Two Sum
- 项目组J2ee程序员的标志,你中招没 转载+评论
- 【附】Cookie和Session的清除,实现网站的退出功能