我的应用程序是这样构建的(我无法发布图片)
UIViewController
|
|----UIView
|
|----UIScrollView
|
|----UIView (here are added my buttons, called contentView)
我想动态添加按钮,具体取决于 WebService 响应。我以编程方式添加这些按钮,一切顺利,但 View 空间不足。为了实现这个目标,我必须调整 View 大小才能正确显示这些新图标,但我无法获得预期的效果。我应该怎么做才能做到这一点?请原谅我糟糕的英语 xD。
== 编辑 ==
这是我向 contentView 添加一些 UISwitch 的代码
- UISwitch *switchDebito=[[UISwitch alloc] initWithFrame:CGRectMake(260, 1080+(cantidadNotificacionesEnconrtadas * 35), 50, 35)];
- [switchDebito setOn:notification.NotificationDebit];
- [self.contentView addSubview:switchCredito];
在第 1 行中,我创建了开关,最终增加了它的高度(不是很重要) 第 2 行毫无意义 第 3 行:这里我们将开关添加到 contentView
最佳答案
在 View Controller 中覆盖 viewWillLayoutSubViews 方法并在其中设置内容 View 框架
- (void)viewWillLayoutSubViews {
[super viewWillLayoutSubViews];
//set your frames here
}
关于ios - 如何在 ScrollView 中调整 subview 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29824036/