iOS——由时间画圆

#pragma mark - UI布局

//#pragma mark - 由时间画圆

//- (void)drawGreenCirWithBegainTime:(float)t1 andEndTime:(float)t2{

//    //调整大小

//    NSInteger jian = kframe.size.width/3.5;

//    CGRect cirFrame = kframe;

//    cirFrame.size.height -= jian;

//    cirFrame.size.width -= jian;

//    cirFrame.origin.x += jian/2;

//    cirFrame.origin.y += jian/2;

//    // 在内存栈中创建一个画布对象 Stack Top

//    UIGraphicsBeginImageContext(cirFrame.size);

//    // 得到刚刚创建的画布对象(取得stack top画布)

//    _context = UIGraphicsGetCurrentContext();

//    //画笔线的颜色

//    CGContextSetRGBStrokeColor(_context,0,1,0,1.0);

//    //线的宽度

//    CGContextSetLineWidth(_context, 1.0);

//    //void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π≈57.3°度=弧度×180°/π 360°360×π/180弧度

//    // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle结束的弧度,clockwise 0为顺时针,1为逆时针。

//    CGContextAddArc(_context, cirFrame.size.height/2, cirFrame.size.height/2, cirFrame.size.height/2, t1, t2, 0); //添加一个圆

//    //绘制路径

//    CGContextDrawPath(_context, kCGPathStroke);

//    //gao

//    UIImage *img2 = UIGraphicsGetImageFromCurrentImageContext();

//    UIGraphicsEndImageContext();

//    _cxtImgView = [[UIImageView alloc ] initWithImage:img2];

//    _cxtImgView.backgroundColor = [UIColor clearColor];

//    //CGRect imageViewFrame = cirFrame;

//    //imageViewFrame.origin.x = 0;

//    //imageViewFrame.origin.y = 0;

//    //_cxtImgView.frame = imageViewFrame;

//    //_cxtImgView.center = _wheelClockView.center;

//    _cxtImgView.frame = cirFrame;

//    _tag += 1;

//    _cxtImgView.tag = _tag;

//    [self.view addSubview:_cxtImgView];

//    //[_wheelClockView addSubview:_cxtImgView];

//}


#pragma mark - 由时间画圆

- (void)drawGreenCirWithBegainTime:(NSString *)t1Str andEndTime:(NSString *)t2Str{

   NSDateFormatter * dateFormatter = [[NSDateFormatteralloc] init];

    dateFormatter.dateFormat =@"yyyy-MM-dd HH:mm:ss";

   NSDate *t1Date = [dateFormatter dateFromString:t1Str];

   NSDate *t2Date = [dateFormatter dateFromString:t2Str];

   NSDate *zeroDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@ 00:00:00",_pickDate]];

   NSLog(@"gao - %@",[dateFormatterstringFromDate:zeroDate]);

   double interval1 = [t1Date timeIntervalSinceDate:zeroDate];

   double interval2 = [t2Date timeIntervalSinceDate:zeroDate];

   NSLog(@"gao - %f--%f",interval1, interval2);

    //表的零点比圆的零点多出pi/2

   double t1 = interval1/(24.0*60.0*60.0)*2*PI-PI/2;

   double t2 = interval2/(24.0*60.0*60.0)*2*PI-PI/2;

   NSLog(@"gao - %f", t1);

   NSLog(@"gao - %f", t2);

    //调整大小

    NSInteger jian =kframe.size.width/3.5;

   CGRect cirFrame = kframe;

    cirFrame.size.height -= jian;

    cirFrame.size.width -= jian;

    cirFrame.origin.x += jian/2;

    cirFrame.origin.y += jian/2;

    

    CGContextSetRGBFillColor (_context1, 0,0, 1.0);//设置填充颜色

    //填充圆,无边框

   CGContextAddArc(_context,150, 30, 30, 0, 2*PI,0); //添加一个圆

    CGContextDrawPath(_context,kCGPathFill);//绘制填充

    

    // 在内存栈中创建一个画布对象 Stack Top

    UIGraphicsBeginImageContext(cirFrame.size);

    // UIGraphicsEndImageContext();

    // 得到刚刚创建的画布对象(取得stack top 画布)

    _context =UIGraphicsGetCurrentContext();

    //画笔线的颜色

    CGContextSetRGBStrokeColor(_context,0,1,0,1.0);

    //线的宽度

    CGContextSetLineWidth(_context,1.0);

    //void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π≈57.3°度=弧度×180°/π 360°360×π/180弧度

    // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle结束的弧度,clockwise 0为顺时针,1为逆时针。

   CGContextAddArc(_context, cirFrame.size.height/2, cirFrame.size.height/2, cirFrame.size.height/2, t1, t2,0); //添加一个圆

    //绘制路径

    CGContextDrawPath(_context,kCGPathStroke);

    //CGContextClearRect(_context, cirFrame);

    //gao

    UIImage *img2 =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

   _cxtImgView = [[UIImageViewalloc ] initWithImage:img2];

    _cxtImgView.backgroundColor = [UIColorclearColor];

    //CGRect imageViewFrame = cirFrame;

    //imageViewFrame.origin.x = 0;

    //imageViewFrame.origin.y = 0;

    //_cxtImgView.frame = imageViewFrame;

    //_cxtImgView.center = _wheelClockView.center;

   _cxtImgView.frame = cirFrame;

   _tag += 1;

    _cxtImgView.tag =_tag;

    [self.viewaddSubview:_cxtImgView];

    //[self clear];

    //[_paintView addSubview:_cxtImgView];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值