首先,获取上下文

CGContextRef context = UIGraphicsGetCurrentContext();

 

画无框矩形

 

//设置矩形填充颜色:红色  
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];  

 

画线

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-06-06
  • 2022-12-23
  • 2021-08-31
相关资源
相似解决方案