我在tabBarController里面的navigationController里面有一个tableView。 我想以编程方式修改tabbar上方的视图,如下所示:
我已尝试添加约束但未成功,也因为我不知道是使用self.view
还是self.bottomLayoutGuide
或self.tableView
或self.navigationController
或者......任何建议?
答案 0 :(得分:1)
试试这个:
button = UIButton(frame: CGRect(x: 0, y: self.view.frame.height - 99, width: self.view.frame.width, height: 50))
button.backgroundColor = UIColor(red: 0, green: 88/255, blue: 171/255, alpha: 1)
button.tintColor = .white
button.titleLabel?.font = UIFont(name: "Helvetica", size: 20)
button.setTitle("YOUR TEXT", for: .normal)
button.addTarget(self, action: #selector(yourAction), for: .touchUpInside)
self.navigationController?.view.addSubview(button)
在我的示例中,它是UIButton
,但它也可以是UIView
与UIView
let view = UIView(frame: CGRect(x: 0, y: self.view.frame.height - 99, width: self.view.frame.width, height: 50))
view.backgroundColor = UIColor(red: 0, green: 88/255, blue: 171/255, alpha: 1)
self.navigationController?.view.addSubview(view)
答案 1 :(得分:0)
试试这个Swift 3.0
这里的底部视图代码。
let bottomview = UIView(frame: CGRect(x: 0, y: self.view.frame.height-63,width:self.view.frame.width, height: 80))
bottomview.backgroundColor = UIColor.red
self.view.addSubview(bottomview)
此处的表格视图代码......
let table: UITableViewController = MyTableViewController()
let tableView: UITableView = UITableView()
tableView.frame = CGRect(x: 0, y:self.navigationController.navigationBar.frame.size.height, width: self.view.frame.width, height: 500)
tableView.dataSource = table
tableView.delegate = table
self.view.addSubview(tableView)
答案 2 :(得分:0)
self.automaticallyAdjustsScrollViewInsets = NO;
然后你会看到导航栏覆盖的tableviewcell和 如果您希望导航栏完全透明
self.navigationController.navigationBar.backgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault;
self.navigationController.navigationBar.shadowImage:[UIImage new];