iOS开发中使用Quartz2D绘图及自定义UIImageView控件

2020-01-14 16:51:23王冬梅

iOS开发中使用Quartz2D绘图及自定义UIImageView控件

说明:系统的UIimage可以替换。而自定义imageview不会变换,因为自定义的view要想换图片,需要重新绘制并渲染一次图片。所以在拿到替换图片的时候,需要重新绘制一次图片,重写setimage方法。
完善后的代码如下:

主控制器中,YYViewController.m文件的代码:

复制代码
//
//  YYViewController.m
//  02-自定义UIimageview
//
//  Created by apple on 14-6-22.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"
#import "YYimageView.h"

@interface YYViewController ()
@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)YYimageView *yyimageView;
@end


复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    //系统的UIImageview的使用
////    1.创建一个UIImageView
//    UIImageView *iv=[[UIImageView alloc]init];
////    2.设置图片
//    iv.image=[UIImage imageNamed:@"me"];
////    3.设置frame
//    iv.frame=CGRectMake(100, 100, 100, 100);
////    4.把创建的自定义的view添加到界面上
//    [self.view addSubview:iv];
//    self.imageView=iv;
    
    
    //自定义UIImageView
    //1.创建
    //2.设置图片
    //3.设置frame
    //4.把创建的自定义的view添加到界面上
    YYimageView *yyiv=[[YYimageView alloc]init];
    yyiv.image=[UIImage imageNamed:@"me"];
    yyiv.frame=CGRectMake(100, 100, 100, 100);
    [self.view addSubview:yyiv];