2 developerwab developerWab 于 2013.01.08 16:26 提问

获得UIImageView的高宽值

需要获取图片的尺寸,高*宽。
然后将值传递到下面的代码:

 UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(25, 5, imgView.size.width, imgView.size.width)];

但是总是不成功,不知道应该怎么实现?谢谢

3个回答

zhanglei5415
zhanglei5415   Rxr 2013.01.09 13:57
已采纳
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(25, 5, imgView.size.width, imgView.size.width)];

你这样创建,这时的UIImageView还没有width及height.UIImageView 尺寸依据它添加的UIImage

UIImage *img=[UIImage imageNamed:@""];
UIImageView *imgView=[[UIImageView alloc] initWithImage:img];
imgView.frame=CGRectMake(25, 5, imgView.size.width, imgView.size.width);
xinyoulingxi1_tong
xinyoulingxi1_tong   2013.01.08 16:45
UIImage *image = [UIImage imageNamed:@"image.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.frame = CGRectMake(0, 0, image.size.width, image.size.height);

希望能帮到你

love_loveec
love_loveec   2013.01.08 16:51

用UIImage尺寸属性获得尺寸。

UIImage *img = [UIImage imageNamed:@"image.png"];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(25, 5, img.size.width, img.size.width)];

或者这样:

UIImageView *imgView=[[UIImageView alloc] initWithImage:img];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!