iOS开发中Quartz2D的基本使用方式举例

2020-01-14 17:25:19于海丽

}


@end


效果(平铺):

 

iOS开发中Quartz2D的基本使用方式举例

代码2:

复制代码
#import "YYimage.h"

 

@implementation YYimage


- (void)drawRect:(CGRect)rect
{
 
    //    1.加载图片到内存中
    UIImage *image = [UIImage imageNamed:@"me"];
    
    
    // 利用OC方法将图片绘制到layer上
  
    // 利用drawInRect方法绘制图片到layer, 是通过拉伸原有图片
        [image drawInRect:CGRectMake(0, 0, 200, 200)];
    
    // 利用drawAsPatternInRec方法绘制图片到layer, 是通过平铺原有图片
//    [image drawAsPatternInRect:CGRectMake(0, 0, 320, 480)];
}


@end


效果(拉伸图片):

 

iOS开发中Quartz2D的基本使用方式举例

代码3:

复制代码
//
//  YYimage.m
//  04-写文字
//
//  Created by 孔医己 on 14-6-10.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

 

#import "YYimage.h"

@implementation YYimage


- (void)drawRect:(CGRect)rect
{
 
    //    1.加载图片到内存中
    UIImage *image = [UIImage imageNamed:@"me"];