【问题标题】:How to add UIButton as bottomView to UIView?如何将 UIButton 作为底部视图添加到 UIView?
【发布时间】:2019-11-13 02:05:40
【问题描述】:

我有一个 UIView 类,在 xib 中我也有一个 MainView,它是一个 UIView。我想将 UIButton 作为底部视图添加到视图中。我需要在 MainView 和底部视图之间提供底部空间 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];

Expected result

Output from above code

【问题讨论】:

  • google iOS 自动布局教程

标签: ios objective-c uiview uibutton


【解决方案1】:

请发现您在此框架上添加了按钮

 self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.MainView.bounds.size.height +30, self.MainView.bounds.size.width, 40.0)];

在这里,您将 y 设置为 height + 30,因此视图不可见。

你应该使用这个。

 self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.MainView.bounds.size.height - 40, self.MainView.bounds.size.width, 40.0)];

此外,如果您想要 16 像素的间隙,您应该使用相同的方法查看其上方的视图。

如果您需要更多帮助,请告诉我

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 2014-02-26
    • 2012-07-20
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多