UIImageView

- (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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容