iPhone UIView - 调整框架以适应子视图 [英] iPhone UIView - Resize Frame to Fit Subviews

查看:22
本文介绍了iPhone UIView - 调整框架以适应子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在添加子视图之后,难道不应该有一种方法来调整 UIView 的框架大小,以便框架是包含所有子视图所需的大小吗?如果您的子视图是动态添加的,您如何确定容器视图的框架需要多大?这不起作用:

Shouldn't there be a way to resize the frame of a UIView after you've added subviews so that the frame is the size needed to enclose all the subviews? If your subviews are added dynamically how can you determine what size the frame of the container view needs to be? This doesn't work:

[myView sizeToFit];

推荐答案

查看 无法让 UIView sizeToFit 做任何有意义的事情

要点是 sizeToFit 用于子类覆盖,在 UIView 中不做任何事情.它为 UILabel 做一些事情,因为它覆盖了由 sizeToFit

The gist is that sizeToFit is for subclasses to override, and doesn't do anything in UIView. It does stuff for UILabel, because it overrides sizeThatFits: which is called by sizeToFit

这篇关于iPhone UIView - 调整框架以适应子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆