本文介绍了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];
推荐答案
查看
要点是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-调整框架大小以适合子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!