//
//  AView.m
//  AutoLayout
//
//  Created by ZhuYi on 16/5/24.
//  Copyright © 2016年 ZY. All rights reserved.
//

#import "AView.h"

@implementation AView

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {
    // Drawing code
    UIImage *image = [UIImage imageNamed:@"dropdown_anim__0005"];
    [image drawInRect:CGRectMake(, , rect.size.width, rect.size.height)];
//    [image drawAsPatternInRect:CGRectMake(0, 0, rect.size.width, rect.size.height)];

}

/**
 *      画三角形
 */
void drawTriangel(){
    //获得当前图形的上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //设置七点
    CGContextMoveToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    //    CGContextAddLineToPoint(ctx, 0, 0);
    //关闭路径
    CGContextClosePath(ctx);
//    [[UIColor redColor] setFill];
//    [[UIColor redColor] set];
    CGContextSetRGBFillColor(ctx, , , , );
    CGContextFillPath(ctx);
}
/**
 *      画矩形
 */
void drawRect(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddRect(ctx, CGRectMake(, , , ));
//    [[UIColor redColor] setStroke];
    CGContextSetRGBStrokeColor(ctx, , , , );
    CGContextStrokePath(ctx);
}

/**
 *      设置状态
 */
void set(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //设置开头和结尾的样式
    CGContextSetLineCap(ctx, kCGLineCapRound);
    //设置转折点的样式
    CGContextSetLineJoin(ctx, kCGLineJoinRound);

    CGContextMoveToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    CGContextSetLineWidth(ctx, );
    CGContextSetRGBStrokeColor(ctx, , , , );
    CGContextStrokePath(ctx);

    CGContextMoveToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    CGContextSetRGBStrokeColor(ctx, , , , );
    CGContextSetLineWidth(ctx, );
    CGContextStrokePath(ctx);
}
/**
 *      画椭圆
 */
void ellipse(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(ctx, , , , );
    CGContextSetLineWidth(ctx, );
    CGContextAddEllipseInRect(ctx, CGRectMake(, , , ));
    CGContextStrokePath(ctx);
}

/**
 *      画圆弧
 */
void arr(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddArc(ctx, , , , , -M_PI_4, );
    CGContextSetLineWidth(ctx, );
    CGContextSetRGBStrokeColor(ctx, , , , );
    CGContextStrokePath(ctx);
}
/**
 *      画圆弧
 */
void cusarr(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );
    CGContextAddArc(ctx, , , , M_PI_2, M_PI, );
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);
}

/**
 *  画文字
 */
void drawText()
{
    // 1.获得上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    // 2.画矩形
    CGRect cubeRect = CGRectMake(, , , );
    CGContextAddRect(ctx, cubeRect);
    // 3.显示所绘制的东西
    CGContextFillPath(ctx);

    // 4.画文字
    NSString *str = @"哈哈哈哈Good morning hello hi hi hi hi";
    //    [str drawAtPoint:CGPointZero withAttributes:nil];

    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    // NSForegroundColorAttributeName : 文字颜色
    // NSFontAttributeName : 字体
    attrs[NSForegroundColorAttributeName] = [UIColor redColor];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:];
    [str drawInRect:cubeRect withAttributes:attrs];
}
void drawImage()
{
    // 1.取得图片
    UIImage *image = [UIImage imageNamed:@"me"];

    // 2.画
    //    [image drawAtPoint:CGPointMake(50, 50)];
    //    [image drawInRect:CGRectMake(0, 0, 150, 150)];
    [image drawAsPatternInRect:CGRectMake(, , , )];

    // 3.画文字
//    NSString *str = @"为xxx所画";
//    [str drawInRect:CGRectMake(0, 180, 100, 30) withAttributes:nil];
}
/**
 *  矩阵操作和上下文栈
 */
void juzhencaozuo(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    //保存上下文栈
    CGContextSaveGState(ctx);

    //矩阵操作
    CGContextRotateCTM(ctx, M_PI_4 * 0.3);
    CGContextScaleCTM(ctx, 0.5, 0.5);
    CGContextTranslateCTM(ctx, , );

    CGContextAddRect(ctx, CGRectMake(, , , ));

    CGContextStrokePath(ctx);

    //回复上下文栈
    CGContextRestoreGState(ctx);

    CGContextAddEllipseInRect(ctx, CGRectMake(, , , ));
    CGContextMoveToPoint(ctx, , );
    CGContextAddLineToPoint(ctx, , );

    // 矩阵操作
    //    CGContextScaleCTM(ctx, 0.5, 0.5);

    CGContextStrokePath(ctx);
}
/**
 *  裁剪
 */
void caijian(){
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextSaveGState(ctx);

    // 0.画圆
    CGContextAddEllipseInRect(ctx, CGRectMake(, , , ));
    // 裁剪
    CGContextClip(ctx);
    CGContextFillPath(ctx);

    // 1.显示图片
    UIImage *image = [UIImage imageNamed:@"me"];
    [image drawAtPoint:CGPointMake(, )];
}
/**
 *  刷帧
 */
- (void)setRadios:(float)radios{
    _radios = radios;
    [self setNeedsDisplay];
}
- (void)shuazhen{
    ) {
        self.radios = ;
    }
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddArc(ctx, , , self.radios, , M_PI * , );
    CGContextStrokePath(ctx);
}
@end

http://www.jianshu.com/p/734b34e82135

mmmmmmmm的更多相关文章

  1. Android 如何有效的解决内存泄漏的问题

    前言:最近在研究Handler的知识,其中涉及到一个问题,如何避免Handler带来的内存溢出问题.在网上找了很多资料,有很多都是互相抄的,没有实际的作用. 本文的内存泄漏检测工具是:LeakCana ...

  2. what is difference in (int)a,(int&)a,&a,int(&a) ?

    This interview question come from a famous communication firm of china. : ) #include <iostream> ...

  3. JAVA基础学习day13--String、StringBuilder与StringBuffer与包装类

    一.String 1.1.String String 类是final修饰的,是顶级类,不可被继承 String 类代表字符串.Java 程序中的所有字符串字面值(如 "abc" ) ...

  4. C/C++中float和double的存储结构

    int main (int argc, char **argv) { float a = 1.0f; cout <<"(int&)a = "<<(i ...

  5. Pictures of Ascii Art

    简述 指尖上的艺术 - 通过键盘上韵律般的敲敲打打,一幅幅美轮美奂的艺术作品便跃然于屏. 这样的画作,包含了无穷的创意,糅合了现代计算机科技与传统绘画艺术,难道还有比这更令人陶醉的美妙事物吗? 简述 ...

  6. UIProgressView-初识IOS

    好几天没更新了,学的时候太紧,没时间复习了都.今天刚好有时间,多更几个. 今天复习的是UIProgressView,我们常见使用在修改某些属性的时候经常用到,比如透明度,今天我们介绍一个简单的使用例子 ...

  7. 项目必备!永无 bug 注释

    佛祖保佑 永无bug 代码注释 // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`-- ...

  8. C语言中,float在内存中的储存方式

    浮点型变量在计算机内存中占用4字节(Byte),即32-bit. 遵循IEEE-754格式标准. 一个浮点数由2部分组成:底数m 和 指数e. ±mantissa × 2exponent (注意,公式 ...

  9. GPS坐标转换 百度地图API调用

    1 如果GPS输出的值是DD.DDDDDDDD格式的,直接调用地图API的转换函数处理,就可以正常显示2 如果GPS输出的值是DD.MMMMMMMM格式的,就需要先进行分转度处理,然后再调API,就可 ...

随机推荐

  1. iOS手动管理内存

    虽然iOS已经有了ARC帮你自动管理内存,但在有些项目中必须采用手动的方式,而且在懂得手动管理内存的情况下会是自己的代码更加完善 众所周知,基于手动管理内存的情况下必然涉及到 relese  reta ...

  2. springMVC3学习(四)--访问静态文件如js,jpg,css

    如果你的DispatcherServlet拦截的是*.do这样的URL,就不存在访问不到静态资源的问题 如果你的DispatcherServlet拦截了"/"所有的请求,那同时对* ...

  3. FpGrowth算法

    FpGrowth算法 频繁项集与关联规则挖掘(2)--FpGrowth算法   上一篇介绍了关联规则挖掘的一些基本概念和经典的Apriori算法,Aprori算法利用频繁集的两个特性,过滤了很多无关的 ...

  4. JAVA多线程经典问题 -- 生产者 消费者

    工作2年多来一直也没有计划写自己的技术博客,最近辞职在家翻看<thingking in JAVA>,偶尔看到了生产者与消费者的一个经典的多线程同步问题.本人在工作中很少使用到多线程以及高并 ...

  5. enode框架step by step之saga的思想与实现

    enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...

  6. .NET依托CLR进行的内存的管理

    看了http://www.cnblogs.com/liulun/p/3145351.html  不错,补习下相关技术.. 正文: .NET依托CLR进行的内存的管理 有了CLR 基本不需要担心.net ...

  7. [解决]Windows Server 2012 不能安装IE版的Flash

    1.问题描述 在server 2012下安装IE版的Flash提示包含最新版本 2.解决方法 2.1.开启“桌面体验”功能 2.2.关闭“IE增强的安全配置”功能 3.重启计算机后安装Flash

  8. ThinkPHP中连接mysql数据库的四种实用和通用的连接方法

    ThinkPHP内置了抽象数据库访问层,把不同的数据库操作封装起来,我们只需要使用公共的Db类进行操作,而无需针对不同的数据库写不同的代码和底层实现,Db类会自动调用相应的数据库适配器来处理.目前的数 ...

  9. php中的foreach函数

    Foreach 函数(PHP4/PHP5) foreach 语法结构提供了遍历数组的简单方式. foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信 ...

  10. 熬之滴水成石:Spring--精简的J2EE(7)

                                              49--持久性 关于持久性在最早的Delphi单元中,就曾介绍过.持久性是数据库中读取,保存,或删除数据的过程.毫无 ...