Quartz2D~图片裁剪

代码:

//
// QiDraw.m
// 
//
// Created by QiZhang on 11/26/15.
//
//

#import "QiDraw.h"

@implementation QiDraw


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// UIImage *image = [UIImage imageNamed:@"头像"];
// [image drawAtPoint:CGPointZero];
// [image drawInRect:CGRectMake(0, 0, 100, 100)];

    UIRectClip(CGRectMake(0, 0, 100, 100)); // 设置裁剪区,超过裁剪区的部分将会被裁减掉
    UIImage *pImage = [UIImage imageNamed:@"001"];
    [pImage drawAsPatternInRect:rect];

// [self drawText];


}


- (void)drawText
{
    // Drawing code
    NSString *text = @"dsfjaewdsfjaewiojtglkadsjgaadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgasldkfjdslffddddaewiojtglkadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgdslffdddddddddddddddddddsfjaewiojtglkadsjgasldkfjdslffdddddddddddddddddddsfjaewiojtglkadsjgasl";
    CGRect textFrame = CGRectMake(0, 0, 200, 200);
    NSDictionary *dict = @{
                           NSFontAttributeName : [UIFont systemFontOfSize:10],
                           NSForegroundColorAttributeName : [UIColor redColor],
                           NSBackgroundColorAttributeName : [UIColor blueColor],
                           NSStrokeWidthAttributeName : @5

                           };
    UIRectFill(textFrame);
    [text drawInRect:textFrame withAttributes:dict];  // 会自动换行
    // [text drawAtPoint:CGPointZero withAttributes:dict]; // 不会自动换行
}


@end

结果:
Quartz2D~图片裁剪_第1张图片

你可能感兴趣的:(quartz,图片,2d)