Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hisoka0917/308ab78ce764bb23b8904959d8d9eeb5 to your computer and use it in GitHub Desktop.
Save hisoka0917/308ab78ce764bb23b8904959d8d9eeb5 to your computer and use it in GitHub Desktop.
UITableViewController with a fixed bottom button
class MyTableViewController: UITableViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
bottomButton.size = CGSize(width: self.view.width, height: 50)
bottomButton.translatesAutoresizingMaskIntoConstraints = false
bottomButton.addTarget(self, action: #selector(bottomButtonClick), for: .touchUpInside)
self.navigationController?.setToolbarHidden(false, animated: animated)
let btn = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(bottomButtonClick))
let fixspace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
fixspace.width = CGFloat.leastNormalMagnitude
self.navigationController?.toolbar.items = [fixspace, btn, fixspace]
self.navigationController?.toolbar.addSubview(bottomButton)
self.navigationController?.toolbar.leadingAnchor.constraint(equalTo: bottomButton.leadingAnchor).isActive = true
self.navigationController?.toolbar.trailingAnchor.constraint(equalTo: bottomButton.trailingAnchor).isActive = true
self.navigationController?.toolbar.topAnchor.constraint(equalTo: bottomButton.topAnchor).isActive = true
self.navigationController?.toolbar.bottomAnchor.constraint(equalTo: bottomButton.bottomAnchor).isActive = true
self.navigationController?.toolbar.clipsToBounds = true
}
@objc private func bottomButtonClick() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment