zoukankan      html  css  js  c++  java
  • 路径构造

    1 前言

    构造和绘制路径,能够在图形环境上画任意形状.

    2 代码实例

    ZYViewControllerView.m

    [plain] view plaincopy
    1. - (void)drawRect:(CGRect)rect{  
    2.     //创建路径 创建一个新的 CGMutablePathRef 类型的可变路径并返回其句柄。  
    3.     CGMutablePathRef path = CGPathCreateMutable();  
    4.     /* How big is our screen? We want the X to cover the whole screen */  
    5.     //范围为整个屏幕  
    6.     CGRect screenBounds = [[UIScreen mainScreen] bounds];  
    7.     //从左上角开始画路径 将路径上当前画笔位置移动到 CGPoint 类型的参数指定的点。  
    8.     CGPathMoveToPoint(path, NULL,screenBounds.origin.x, screenBounds.origin.y);  
    9.     //从左上角连线到右下角 从画笔当前位置向指定位置绘制一条线段。  
    10.     CGPathAddLineToPoint(path,NULL, screenBounds.size.width, screenBounds.size.height);  
    11.     //开始另一点从右上角  
    12.     CGPathMoveToPoint(path,NULL, screenBounds.size.width, screenBounds.origin.y);  
    13.     //从右上角到左下角  
    14.     CGPathAddLineToPoint(path,NULL, screenBounds.origin.x, screenBounds.size.height);  
    15.     //获得当前图形的上下文  
    16.     CGContextRef currentContext = UIGraphicsGetCurrentContext();  
    17.     /* Add the path to the context so we candraw it later */  
    18.     //添加路径到路径上下文中 向图形环境上添加一个路径(由一个路径句柄指定),该路径已经准备好被绘制。  
    19.     CGContextAddPath(currentContext,path);  
    20.     //设置蓝色  
    21.     [[UIColor blueColor] setStroke];  
    22.     //画图 在图形环境上绘制指定路径  
    23.     /*kCGPathStroke  
    24.     画线来标记路径的边界或边缘,使用选中的绘图色。  
    25.     kCGPathFill  
    26.     用选中的填充色,填充被路径包围的区域。  
    27.     kCGPathFillStroke  
    28.     组合绘图和填充。用当前填充色填充路径,并用当前绘图色绘制路径边界。下面我们会看到一个使用此方 法的例子。  
    29.     */  
    30.     CGContextDrawPath(currentContext, kCGPathStroke);  
    31.     //释放路径  
    32.     CGPathRelease(path);  
    33. }  

    隐藏状态条

    此例中,我要隐藏程序的状态条:请找到 Info.plist,并增加一个 UIStatusBarHidden 键,将其值设置为 YES


    运行结果


    3 结语

    以上是所有内容,希望对大家有所帮助。

    Demo实例下载:http://download.csdn.net/detail/u010013695/5374923

  • 相关阅读:
    在yii中使用Filter实现RBAC权限自动判断
    关于WEB设计透明和阴影
    一句话扯扯数据结构的概念点
    Console API Google 浏览器开发人员工具使用
    git提交项目时候,忽略一些文件
    学习笔记 如何解决IE6 position:fixed固定定位问题{转载}
    [转载]yii jquery折叠、弹对话框、拖拽、滑动条、ol和ul列表、局部内容切换
    Jquery 常用方法经典总结【砖】
    PHP中冒号、endif、endwhile、endfor这些都是什么
    [转载]救命的PHP代码
  • 原文地址:https://www.cnblogs.com/yulang314/p/3720618.html
Copyright © 2011-2022 走看看