UIKit绘图方法

Main.storyboard

 

CustomView.h

#import <UIKit/UIKit.h>

 

@interface CustomView : UIView

 

@end

//

//  CustomView.m

//  5B03.UIKit绘图方法

//

//  Created by huan on 16/1/29.

//  Copyright © 2016 huanxi. All rights reserved.

//

 

#import "CustomView.h"

 

@implementation CustomView

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

 */

- (void)drawRect:(CGRect)rect {

//    // Drawing code

//    //以前一直都要获取上下文,

//    //UIKit的方法,虽然不用获取上下文,但内部最终都会获取上下文绘制

//    //使用UIKit绘图方法

//    //画实心

//    UIRectFill(CGRectMake(10, 10, 100, 100));

//    //画空心

//    UIRectFrame(CGRectMake(10, 110, 50, 50));

    

    CGContextRef ctx = UIGraphicsGetCurrentContext();

//    //每调用一次,往上下文添加路径

//    CGContextMoveToPoint(ctx, 10, 10);

//    CGContextAddLineToPoint(ctx, 100, 100);

    

    //先把所有的路径定义好,然后一次往往上下文中添加

    CGMutablePathRef path = CGPathCreateMutable();

    //设置圆的路径

    CGPathAddEllipseInRect(path, nil, CGRectMake(10, 10, 100, 100));

    CGPathAddEllipseInRect(path, nil, CGRectMake(20, 20, 80, 80));

    

    //添加弧的路径

//    CGPathAddArc(<#CGMutablePathRef  _Nullable path#>, <#const CGAffineTransform * _Nullable m#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#bool clockwise#>);

    

    

    //添加线路径

//    CGPathAddLines(<#CGMutablePathRef  _Nullable path#>, <#const CGAffineTransform * _Nullable m#>, <#const CGPoint * _Nullable points#>, <#size_t count#>)

    //把路径添加到上下文

    CGContextAddPath(ctx, path);

    //渲染

    CGContextStrokePath(ctx);

    

    //开发过程中,ARC环境 c语言的资源不会自动释放

    //什么情况下创建的c语言资料,需要释放 create,retain,copy创建的数据要释放

//    CGPathRelease(path);

    //通用

    CFRelease(path);

}

 

 

@end

转载于:https://www.cnblogs.com/Lu2015-10-03/p/5177710.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值