开发者社区> 问答> 正文

获得UIImageView的高宽值

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

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

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

展开
收起
爵霸 2016-03-26 09:53:40 1757 0
1 条回答
写回答
取消 提交回答
  • 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);
    2019-07-17 19:15:25
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载