iOS图片的填充方式UIImageView(contentMode)有什么不同
2017-11-20 09:18
1406 查看
iOS图片的填充方式UIImageView(contentMode)有什么不同
2017-04-28 10:40 2681人阅读 评论(0) 收藏 举报UIViewContentModeScaleAspectFit, //这个图片都会在view里面显示,并且比例不变 这就是说 如果图片和view的比例不一样 就会有留白如下图1
图1
UIViewContentModeScaleAspectFill, // 这是整个view会被图片填满,图片比例不变 ,这样图片显示就会大于view如下图2
图2
既然要求不高 又不能留白 那我就可以用第二种 可是这样就超出位置了, 截掉就可以了!
然后完整过程就两步
[self.prp_imageViewsetContentMode:UIViewContentModeScaleAspectFill];
self.prp_imageView.clipsToBounds = YES;
完美解决 以下是效果图
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
其他更详细的属性介绍:
UIView有个UIViewContentMode类型的属性contentMode,可以通过它来修改视图的内容显示模式。
view sourceprint?
01.
typedef NS_ENUM(NSInteger, UIViewContentMode) {
02.
UIViewContentModeScaleToFill,
03.
UIViewContentModeScaleAspectFit,
// contents scaled to fit with fixed aspect. remainder is transparent
04.
UIViewContentModeScaleAspectFill,
// contents scaled to fill with fixed aspect. some portion of content may be clipped.
05.
UIViewContentModeRedraw,
// redraw on bounds change (calls -setNeedsDisplay)
06.
UIViewContentModeCenter,
// contents remain same size. positioned adjusted.
07.
UIViewContentModeTop,
08.
UIViewContentModeBottom,
09.
UIViewContentModeLeft,
10.
UIViewContentModeRight,
11.
UIViewContentModeTopLeft,
12.
UIViewContentModeTopRight,
13.
UIViewContentModeBottomLeft,
14.
UIViewContentModeBottomRight,
15.
};
实例代码:
view sourceprint?
1.
CGRect rect = self.view.frame;
2.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
3.
imageView.contentMode = UIViewContentModeTop;
4.
imageView.image = [UIImage imageNamed:@
demoImage
];
5.
[self.view addSubview:imageView];
UIViewContentModeScaleToFill
根据视图的比例去拉伸图片内容。
UIViewContentModeScaleAspectFit
保持图片内容的纵横比例,来适应视图的大小。
UIViewContentModeScaleAspectFill
用图片内容来填充视图的大小,多余得部分可以被修剪掉来填充整个视图边界。
UIViewContentModeRedraw
这个选项是单视图的尺寸位置发生变化的时候通过调用setNeedsDisplay方法来重新显示。
UIViewContentModeCenter
保持图片原比例在视图中间显示图片内容
如果视图大小小于图片的尺寸,则图片会超出视图边界,下面类同
UIViewContentModeTop
保持图片原比例在视图中间顶部显示图片内容
UIViewContentModeBottom
保持图片原比例在视图中间底部显示图片内容
UIViewContentModeLeft
保持图片原比例在视图中间左边显示图片内容
UIViewContentModeRight
保持图片原比例在视图中间右边显示图片内容
UIViewContentModeTopLeft
保持图片原比例在视图左上角显示图片内容
UIViewContentModeTopRight
保持图片原比例在视图右上角显示图片内容
UIViewContentModeBottomLeft
保持图片原比例在视图左下角显示图片内容
UIViewContentModeBottomRight
保持图片原比例在视图右下角显示图片内容
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
sdwebimage 图片大小 处理
原创 2016年04月28日09:45:35
标签:
ios /
图片
3851
遇到问题 设置了一个宽高 固定的(1:1 )的 图片 用 sdwebimage 加载的时候显示出来的图片会被压缩或者拉伸,想让显示 一部分的图片(保持图片不变形) 所以对图片进行剪裁代码如下
[cell.imagesd_setImageWithURL:[NSURLURLWithString:[NSStringstringWithFormat:@"%@%@",URL_HOST,ImagArray[0]]]placeholderImage:[UIImageimageNamed:@"futrue"]completed:^(UIImage*image,NSError *error, SDImageCacheType cacheType,NSURL *imageURL)
{
CGSize newSize;
CGImageRef imageRef =nil;
if ((image.size.width /
image.size.height) < 1)
{
newSize.width = image.size.width;
newSize.height = image.size.width ;
imageRef = CGImageCreateWithImageInRect([imageCGImage], CGRectMake(0,fabs(image.size.height -
newSize.height) / 2, newSize.width,
newSize.height));
} else {
newSize.height = image.size.height;
newSize.width = image.size.height *1;
imageRef = CGImageCreateWithImageInRect([imageCGImage], CGRectMake(fabs(image.size.width -
newSize.width) / 2, 0,
newSize.width, newSize.height));
}
cell.image.image =[UIImageimageWithCGImage:imageRef];
}];
后来发现对 iimageView 做入下处理 就可实现
showSpecialityCatoryImage.contentMode =UIViewContentModeScaleAspectFill;
showSpecialityCatoryImage.clipsToBounds = YES;
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
UIImageView 的contentMode属性应用
原创 2013年12月19日14:45:29
标签:
contentMode /
UIViewContentModeSca
45889
UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:
UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
例如:
1。显示正常的图片
[cpp] view
plaincopy
_image = [[UIImageView alloc] init];
image = [UIImage imageNamed:@"12.jpeg"];
_image.backgroundColor = [UIColor brownColor];
_image.clipsToBounds = YES;
_image.frame = CGRectMake(100, 130, 100, 100);
_image.contentMode = UIViewContentModeScaleToFill;
[self.view addSubview:_image];
2。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFill;
3。
[cpp] view
plaincopy
_image.contentMode = UIViewContentModeScaleAspectFit;
、
相关文章推荐
- iOS图片的填充方式UIImageView(contentMode)有什么不同
- ios中UIImageView展现图片的不同处理方式
- iOS 图片填充 UIImageView (contentMode)
- ios中UIImageView展现图片的不同处理方式
- UI-UIImageView的图片填充方式(contentMode)_图片作为控件背景图的拉伸方式(stretch)介绍
- UIImageView 图片填充模式 contentMode 详解
- iphone,UIImageView展现不同途径的图片的不同处理方式
- ios的UIImage的两种不同的图片加载方式 tom猫
- IOS Swift UIImageView图片的填充模式
- iphone,UIImageView展现不同途径的图片的不同处理方式
- iOS - UIImageView 的contentMode属性,以及图片拉伸stretchableImageWith
- [IOS] 使用UIImageView的contentMode属性, 控制图片显示
- iOS(9) SDWebImage 里面给 UIImageView 加载图片的逻辑是什么样的
- iOS开发UIImage和UIImageView属性介绍,实现图片动画,实现开始/停止按钮效果
- 给iOS项目中添加图片,并通过UIImageView引用和显示该UIImage图片
- iOS UIImageView设置多张图片
- 【IOS】UIImage加载图片的方式以及Assets.xcassets对于加载方法的影响
- IOS中UIImageView使用网络图片
- iOS有关图片处理的总结 (一)------UIImage的加载方式
- iOS_UIImageView的contentMode属性--照片的显示模式