user8398815
user8398815

Reputation:

How to programatically fix a view to a tab bar in Swift?

I have a tableView inside a navigationController inside a tabBarController. I want to programatically fix a view above the tabbar like this:

image.

I have experimented with adding constraints without success, also because I don't know whether to use self.view or self.bottomLayoutGuide of self.tableView or self.navigationController or self.tabBarController.tabBar or ... any suggestions?

Upvotes: 0

Views: 1061

Answers (3)

Arjun Yadav
Arjun Yadav

Reputation: 1429

Try this Swift 3.0

Bottom view code here.

    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)
       

Table view code here...

    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)

Upvotes: -1

Phyber
Phyber

Reputation: 1368

Try this:

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)

In my example, it is a UIButton but it can be a UIView too

Same example with 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)

Upvotes: 1

Zedd
Zedd

Reputation: 204

self.automaticallyAdjustsScrollViewInsets = NO;

then you will see the tableviewcell covered by navigationbar and if you want navigationbar to be full transparency

self.navigationController.navigationBar.backgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault;
self.navigationController.navigationBar.shadowImage:[UIImage new];

Upvotes: 0

Related Questions