一、imageView图片不变形
1、通过设置属性
IOS UIImageView的contentMode属性
2、按原图宽高比例
用到第三方库SDWebImage
[imageView sd_setImageWithURL:[NSURL URLWithString:img] placeholderImage:[UIImage imageNamed:@""] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
CGSize size = image.size;
CGFloat W = size.width;
CGFloat H = size.height;
if (W>H) {
imageView.contentMode = UIViewContentModeScaleAspectFill;
}else{
imageView.layer.contentsRect = CGRectMake(0, 0,1, W/H);
imageView.contentMode = UIViewContentModeScaleToFill;
}
}];
3、参考文档:
IOS 图片不变形显示
ios通过URL获取网络图片的原始大小
iOS 图片处理方法(按比例缩放,指定宽度按比例缩放)
iOS开发 - 根据图片URL获取图片的尺寸(宽高)
iOS 返回一张可以随意拉伸不变形的图片 方法
二、imageView切圆并描边
1、属性设置
-(UIImageView *)imgView{
if (!_imgView) {
_imgView =[[UIImageView alloc]init];
[self.bgImgView addSubview: _imgView];
_imgView.layer.cornerRadius=15.0f;
_imgView.layer.masksToBounds =YES;
_imgView.layer.borderColor = [UIColor whiteColor].CGColor;
_imgView.layer.borderWidth = 2.0;
_imgView.layer.cornerRadius = 16;
_imgView.clipsToBounds = YES;
}
return _imgView;
}
网友评论