首先,获取上下文
 
 CGContextRef context = UIGraphicsGetCurrentContext();
复制代码

  画线
  
//设置画笔线条粗细
  CGContextSetLineWidth(context, 5.0);
  //设置线条样式
  CGContextSetLineCap(context, kCGLineCapButt);
  //设置画笔颜色:黑色
  CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
  //画点连线
  CGContextAddLines(context, points, count);
  //执行绘画
  CGContextStrokePath(context);
复制代码

  画无框矩形
  
//设置矩形填充颜色:红色
  CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
  //填充矩形
  CGContextFillRect(context, rect);
  //执行绘画
  CGContextStrokePath(context);
复制代码

  画有框矩形
  
//设置矩形填充颜色:红色
  CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
  //填充矩形
  CGContextFillRect(context, rect);
  //设置画笔颜色:黑色
  CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
  //设置画笔线条粗细
  CGContextSetLineWidth(context, 1.0);
  //画矩形边框
  CGContextAddRect(context,rect);
  //执行绘画
  CGContextStrokePath(context);
复制代码

  画文字
  
//设置画笔线条粗细
  CGContextSetLineWidth(context, 1.0);
  //设置矩形填充颜色:红色
  CGContextSetRGBFillColor (context, 1.0, 0.0, 0.0, 1.0);
  //设置字体
  UIFont *font = [UIFont boldSystemFontOfSize:31.0];
  //在指定的矩形区域内画文字
  [text drawInRect:rect withFont:font];
复制代码

 

posted on 2014-12-26 21:03  墓厄  阅读(456)  评论(0编辑  收藏  举报