当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS开发(82)之绘制矩形

IOS开发(82)之绘制矩形

2019年05月12日  | 移动技术网移动技术  | 我要评论

1 前言
用 cgpathaddrect 向路径中添加一个矩形,然后在图形环境上绘制这条路径。


2 代码实例
zyviewcontrollerview.m

 

[plain]  - (void)drawrect:(cgrect)rect{ 
    //创建图形路径句柄 
    cgmutablepathref path = cgpathcreatemutable(); 
    //设置矩形的边界 
    cgrect rectangle = cgrectmake(10.0f, 10.0f,200.0f, 300.0f); 
    //添加矩形到路径中 
    cgpathaddrect(path,null, rectangle); 
    //获得上下文句柄 
    cgcontextref currentcontext = uigraphicsgetcurrentcontext(); 
    //添加路径到上下文中 
    cgcontextaddpath(currentcontext, path); 
    //填充颜色 
    [[uicolor colorwithred:0.20f green:0.60f blue:0.80f alpha:1.0f] setfill]; 
    //设置画笔颜色 
    [[uicolor browncolor] setstroke]; 
    //设置边框线条宽度 
    cgcontextsetlinewidth(currentcontext,5.0f); 
    //画图 
    cgcontextdrawpath(currentcontext, kcgpathfillstroke); 
    /* 释放路径 */ 
    cgpathrelease(path); 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网