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

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

#import "YYimageView.h"

@implementation YYimageView

//重写drawRect:方法
- (void)drawRect:(CGRect)rect
{
    [self.image drawInRect:rect];
}

@end


在主控制器中,模仿系统自带的UIImageView的使用过程,实现同样的效果。
复制代码
//
//  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 ()

@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];
    
    
    //自定义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];

}
@end


三、完善

 

存在的问题?

在界面上,添加一个按钮,要求点击按钮,能够实现图片的切换。

复制代码
//
//  YYViewController.m