ios 在 subview 中自动调整 uilabel 大小

标签 ios uiview

布局:

  • (UIView *)容器
    • (UIView *)项目
      • (UIView*)subItemsContainer
        • (UIView *子项目

从我做的容器中:

UIView *someItemContentView = --code for an item goes here--;
[someItemContentView sizeToFit];
[self.item.subItemsContainer addSubView:someItemContentView];
[self.item.subItemsContainer sizeToFit];
[self.item sizeToFit];
[self sizeToFit];

但是,subItem 仍被剪裁到其框架。这意味着框架“尺寸不合适”。这不是动态调整所有 View 大小的正确方法吗?

最佳答案

sizeToFit 调用 sizeThatFits 来确定要使用的大小。但正如文档所说:

The default implementation of this method returns the size portion of the view’s bounds rectangle.

这基本上意味着默认实现不执行任何操作,并且由子类来实现适当的 sizeThatFits 行为。

关于ios 在 subview 中自动调整 uilabel 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9539872/

相关文章:

iphone - touchesMoved 工作速度不够快

ios - 在查询中合并两个解析表

ios - 如果用户触摸 UIImageView 则退出键盘

ios - UIView touchesEnded 事件在第一次点击时不调用,但在再次点击时调用

cocoa-touch - 在没有 UITabBar 或 UINavigationBar 的 iOS 中编排多个 View 的最佳方式?

objective-c - 核心剧情: How to position the axis title for two y-axes at the same height?

ios - 登录后自动将用户导航到 Swift 3.0 中的新 ViewController

ios - 使用 automaticallyLoadedAssetKeys 和 "duration"初始化 AVPlayerItem

ios - `UICollectionViewLayout` 如何访问不可见单元格的数据?

ios - UIView圆形 mask 动画