如何在UITableView内的UITabBar顶部添加UIButton

时间:2019-02-02 14:19:35

标签: swift uitableview uibutton constraints

有人知道我如何在UITableView中创建UIButton(约束高度:35,前导:0,尾部:0,UITabBar的底部空间:0,底部空间为UITabBar:0),该UITableView的底部间距为UITabBar,在UITableView中实现UITableViewController?

到目前为止我尝试过的事情:

    let btn = UIButton()
    btn.setTitle("Test Button text", for: .normal)
    btn.tintColor = UIColor.white
    btn.backgroundColor = UIColor.darkGray
    self.view.addSubview(btn)
    btn.translatesAutoresizingMaskIntoConstraints = false
    btn.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 0).isActive = true
    btn.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
    btn.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: 0).isActive = true
    btn.heightAnchor.constraint(equalToConstant: 35).isActive = true

1 个答案:

答案 0 :(得分:0)

继承Uitabbar并将其分配给您的标签栏。然后在类中添加您的按钮代码。不要忘记取消选中选项卡的cliptobound属性。