Creating a UIView that sticks to bottom of UITableView

前端 未结 7 741
一个人的身影
一个人的身影 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:16

    Actually, you can add UIButton to stick in bottom (or header) of the view, it doesn't matter if you're using UITableViewController or UIViewController

    Swift 3

    Create Button:

    For X and Y I apply the entire view size, this will allow me to add margin with - the amount I like. Then, just set size and width.

    let myButton: UIButton = UIButton(CGRect(x: self.view.bounds.size.width - 66, y: self.view.bounds.size.height - 66, width: 50, height: 50))
    

    Note

    See how the width and height are 66? Well, you need to add your margin to the height and width of the button. In this case, 50 + 16 = 66. Also, add you background color and other properties, that way your button is visible.

    Add View to NavigationController

    self.navigationController?.view.addSubview(myButton)
    

    I'm sure you can figure out how to do this in Swift 2, 1 or Objective-C.

提交回复
热议问题