Programmatical Floating Button over tableView
That's because self.view = UITableView inside UITableViewController
, so you need to implement scrollViewDidScroll
class TableViewController: UITableViewController {
let button = UIButton(frame: CGRect(x: 150, y: 550, width: 75, height: 75))
override func viewDidLoad() {
super.viewDidLoad()
button.backgroundColor = .yellow
button.setTitle("To Jobs", for: .normal)
self.view.addSubview(button)
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
button.frame.origin.y = 550 + scrollView.contentOffset.y
}
}
Insert a floating action button on UITableView in Swift
If you currently using tableViewController then no , you must subclass UIViewController add UItableView and your floating button to it
Or you may override scollviewDidScroll and change button y according to tableview current offset
drag scrollview as IBOutlet and set it's delegate to the viewController
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let off = scrollView.contentOffset.y
btn.frame = CGRect(x: 285, y: off + 485, width: btn.frame.size.width, height: btn.frame.size.height)
}
code snapshot
in action
see in action
iOS floating button over table view
Perhaps adding a toolbar with buttons at the bottom would be a better approach?
Floating button over UItableview using storyboards
I think best thing you have to do is to create a UIViewController
and add it a UITableView
. Then you can add also the UIButton
you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add <UITableViewDataSource,UITableViewDelegate>
to your view controller interface.
How to put buttons over UITableView which won't scroll with table in iOS
One solution to this is to extend UIViewController
instead of UITableViewController
. You will need to add your own table view and set everything up. Then you can add your button's to the view controller's view instead of the table view.
Related Topics
Context Menu Not Updating in Swiftui
Instagram Explorer Searchbar and Tableview
Closure Use of Non-Escaping Parameter - Swift 3 Issue
Realitykit - How to Edit or Add a Lighting
Typealias of Generic Class in Swift
Countforfetchrequest in Swift 2.0
Make a Type Itself -- Not Its Instances -- Conform to a Protocol
Require Associatedtype to Be Representable in a @Convention(C) Block
Urlsessiondelegate's Didwritedata Not Call When App Is Going to Background in iOS12
Core Data: Rename Attribute Without Having Issues with Users and Their Current Data
Testing Protocol Conformance with Associated Types
Scenekit Won't Scale a Dynamic Body
Can a Subclass Override a Function and Make More Restrictive Return
Swift: Copy Information Selected by User in Abpersonviewcontroller to Dictionary
Swiftui: Navigationlink Not Working If Not in a List
How to I Turn Off the Ambient Light in Scene Kit (With Swift)
Need Detailed Explanation for Memoize Implementation in Swift (Wwdc 14, Session 404)
Module Compiled with Swift 4.0 Cannot Be Imported in Swift 3.0.2