我有一个 UIView 类,在 xib 中我也有一个 MainView,它是一个 UIView。我想将 UIButton 作为 BottomView 添加到 View 中。我需要在 MainView 和 BottomView 之间提供底部空间 16。我该怎么做?
self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.MainView.bounds.size.height +30, self.MainView.bounds.size.width, 40.0)];
[self.bottomView setBackgroundColor:[UIColor greenColor]];
self.selectBtn= [UIButton buttonWithType: UIButtonTypeRoundedRect];
[self.selectBtn setFrame:CGRectMake(0,20,100,40)];
[self.selectBtn setTitle:@"Select" forState:UIControlStateNormal];
[self.selectBtn addTarget:self action:@selector(selectButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomView addSubview:self.selectBtn];
[self addSubview:self.bottomView];
最佳答案
请发现您在此框架上添加了按钮
self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.MainView.bounds.size.height +30, self.MainView.bounds.size.width, 40.0)];
在这里,您将 y 设置为高度 + 30,因此它在 View 中不可见。
你应该使用这个。
self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.MainView.bounds.size.height - 40, self.MainView.bounds.size.width, 40.0)];
此外,如果您想要 16 像素间隙,您应该使用相同的方法在其上方的 View 。
如果您需要更多帮助,请告诉我
关于ios - 如何将UIButton作为bottomView添加到UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56852222/