需要获取图片的尺寸,高*宽。
然后将值传递到下面的代码:
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(25, 5, imgView.size.width, imgView.size.width)];
但是总是不成功,不知道应该怎么实现?谢谢
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);
UIImage *image = [UIImage imageNamed:@"image.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
希望能帮到你
用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];