我试图理解以下问题。
我创建了一个这样的视图:
UIView *subNavigation = [[UIView alloc] initWithFrame:CGRectMake(0.0 0.0, 0.0, 70.0)];
之后,我正在循环运行以将按钮添加到该 subNavigation 视图,但我不想立即显示按钮:
for (int i = 0; i < 5; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(leftOrigin, 0.0, 145.8, MENU_BUTTON_HEIGHT);
leftOrigin += 145.8;
[button setBackgroundColor:[UIColor whiteColor]];
[button setTitle:@"Button Content" forState:UIControlStateNormal];
[button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
[button setTag:i];
[subNavigation addSubview:button];
}
所以创建了宽度为 0.0 的 subNavigation。添加 subNavigation 时我不想看到按钮,但我愿意。如何使所有子视图调整到其父视图的框架宽度/高度?
非常感谢您的帮助!