Creating a UIView that sticks to bottom of UITableView

前端 未结 7 738
一个人的身影
一个人的身影 2021-01-05 06:47

I have a grouped UITableView and I\'d like to add a UIButton to the very bottom of my UITableView. I\'m using Storyboard and a UITableViewControlle

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 07:07

    I have achieved this with a TableViewController in swift 1.2 by doing the following (in case people come across this like I did while looking for swift solution).

    Once you have your TableViewController on your storyboard drag a View onto the controller. Set it up as you desire and right-click(or ctrl-click) and drag into the source to create an IBOutlet. Then click and drag the view to the top bar . Change to the source for the TableViewController and you will need to derive UIScrollViewDelegate. You will need to set tableView.delegate = self and then you can do the following

    self.tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, floatingView.frame.height, 0.0)
            self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0, 0.0, floatingView.frame.height, 0.0)
    
            floatingView.frame.origin.y = self.tableView.bounds.origin.y + self.tableView.frame.height - floatingView.frame.height
            floatingView.autoresizingMask = UIViewAutoresizing.FlexibleTopMargin
            self.view.addSubview(floatingView)
    

    And then

    override func scrollViewDidScroll(scrollView: UIScrollView) {
    
            floatingView.frame = CGRectMake(self.floatingView.frame.origin.x, self.tableView.bounds.origin.y + self.tableView.frame.height - floatingView.frame.height, self.floatingView.frame.size.width, self.floatingView.frame.size.height)
        }
    

提交回复
热议问题