//注意这是加载图片最简单的方式;这张图片会被缓存到缓存中,加载速度较快;
UIImage *image = [UIImage imageNamed:@"1.jpg"];
//图片的显示是需要载体的;需要放在UIImageView;
UIImageView *imgView = [[UIImageView alloc]init];
//图片显示在屏幕上的大小是由载体控制的;
//现在把载体的大小设置成图片的大小,使用图片的大小设置UIImageView的长宽;
imgView.frame = CGRectMake(0, 0, 375, 667);
imgView.backgroundColor = [UIColor yellowColor];
[imgView setImage:image];
[self.view addSubview:imgView];
//图片的显示模式;
/*
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
//内容模式;
//注意:UIViewContentModeScaleToFill是默认的显示效果;
/*
UIViewContentModeScaleToFill:拉伸充满整个载体;
UIViewContentModeScaleAspectFit:拉伸不改变比例,充满最小的一边;
UIViewContentModeScaleAspectFill:拉伸不改变比例,充满最大的一边;
*/
imgView.contentMode = UIViewContentModeScaleAspectFill;
原图
原图.png
UIViewContentModeScaleToFill:拉伸充满整个载体;
ScaleToFill.png
UIViewContentModeScaleAspectFit:拉伸不改变比例,充满最小的一边;
ScaleAspectFit.png
UIViewContentModeScaleAspectFill:拉伸不改变比例,充满最大的一边;
ScaleAspectFill.png
网友评论