开发者社区> 问答> 正文

在顶层UITableViewController上创建UIButton,就像Airbnb一样

如何在UITableViewController就像AirBnB map.

在屏幕截图中突出显示红色。 https://i.stack.imgur.com/bvSVnl.jpg

展开
收起
游客5akardh5cojhg 2019-12-13 14:20:19 445 0
1 条回答
写回答
取消 提交回答
  • 先创建一个按钮,然后重写函数滚动视图DidScroll():

    import UIKit
    
     class YourTableViewController: UITableViewController {
    
     private let button = UIButton(type: UIButton.ButtonType.custom) as UIButton
    
    override func viewDidLoad() {
        let image = UIImage(named: "Image.png")
        button.frame = CGRect(x: yourXpos, y: yourYPos, width: 60, height: 60)
        button.setImage(image, for: .normal)
        button.clipsToBounds = true
        button.layer.cornerRadius = 30
        button.addTarget(self, action: #selector(buttonClicked(_:)),    for:.touchUpInside)
        areaOfTableView.addSubview(button)
    }
    
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let  offset = self.areaOfTableView.contentOffset.y
    
       button.frame = CGRect(x: yourXpos, y:   offset + yourYpos, width: btn.frame.size.width, height: btn.frame.size.height)
      }
    
    @objc private func buttonClicked(_ button: UIButton) {
        // Action when you tapped the button
       }
    
    }
    
    2019-12-13 14:20:57
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载