作者:princess-小熙_351 | 来源:互联网 | 2023-09-23 14:52
自定义View05自定义基本的UIImageView一代码ViewControllermWMImageViewm二图示自定义View05——自定义基本的UIImageView一、
- 自定义View05自定义基本的UIImageView
- 一代码
- ViewControllerm
- WMImageViewm
- 二图示
自定义View05——自定义基本的UIImageView
一、代码
1. ViewController.m
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];UIImageView *imageView = [[UIImageView alloc]init];UIImage * image = [UIImage imageNamed:@"me"];[imageView setImage:image];[imageView setFrame:CGRectMake(100, 100, 100, 100)];[self.view addSubview:imageView];UIImageView *imageView2 = [[UIImageView alloc]init];UIImage * image2 = [UIImage imageNamed:@"me"];[imageView2 setImage:image2];[imageView2 setFrame:CGRectMake(210, 100, 100, 100)];[self.view addSubview:imageView2];}@end
2.WMImageView.m
#import "WMImageView.h"@implementation WMImageView- (void)drawRect:(CGRect)rect {[_image drawInRect:rect];
}-(void)setImage:(UIImage *)image{_image = image;[self setNeedsDisplay];
}@end
二、图示