- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//1.1 创建UIImageView对象
self.imageView = [[UIImageView alloc]init];
//2.0 加到控制器的view中
[self.view addSubview:self.imageView];
//1.2 设置frame
// self.imageView.frame = CGRectMake(100, 100, 200, 75);
//屏幕适配
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(100);
make.centerX.equalTo(self.view.mas_centerX);
make.width.mas_equalTo(200);
make.height.mas_equalTo(75);
}];
//1.3 设置背景
self.imageView.backgroundColor = [UIColor grayColor];
// self.imageView setBackgroundColor:[UIColor grayColor];
//1.4 设置图片
self.imageView.image = [UIImage imageNamed:@"color0"];
//1.5 设置图片的内容模式
/*
//带有Scale,标明图片按比例进行缩、放
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, //按自身图片比例缩放
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw, //重新绘制(核心绘图)drawRect
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
//裁剪多余的部分
self.imageView.clipsToBounds = YES;
}