您的位置:首页 > 产品设计 > UI/UE

让UIImageView适应图片的大小

2015-12-09 21:47 489 查看
我在一个UIImageView中加入了一张图片,我想让这个图片的尺寸作为该UIImageView的尺寸。

//创建imgV视图
-(void)createImgV
{
//创建视图展示
_imgV = [[UIImageView alloc] initWithFrame:CGRectZero];

_imgV.backgroundColor=[UIColor yellowColor];

//    _imgV.contentMode = UIViewContentModeScaleAspectFit;

_imgV.backgroundColor=[UIColor yellowColor];

_imgV.contentMode=UIViewContentModeScaleToFill;

[self addSubview:_imgV];
}

-(void)setImgName:(NSString *)imgName
{
_imgName = imgName;

[_imgV setImageWithURL:[NSURL URLWithString:_imgName]];

_imgV.frame=CGRectMake(0, 0, _imgV.image.size.width, _imgV.image.size.height);
}


先设为CGRectZero,再赋值也可以!!!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: