代码之家  ›  专栏  ›  技术社区  ›  King

在tableView swift的底部使用google文本提供动力

  •  -3
  • King  · 技术社区  · 7 年前

    我有一个应用程序,我使用谷歌自动完成搜索,但我必须为它编写我的网络代码。现在的问题是,如何在tableView的底部显示由Google文本提供支持的页面?我已经在网上查询了资源,但没有任何选择。提前谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   Shruti Thombre    7 年前

    您可以在页脚视图中添加图像:

    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
        {
            if(section == tableView.numberOfSections - 1)
            {
                let footerView = UIView.init(frame: CGRect(x:0, y:0, width:tableView.frame.size.width, height:100))
                footerView.backgroundColor = UIColor.clear
                let imageView: UIImageView = UIImageView.init(frame: CGRect.init(x: 40, y: 0, width: footerView.frame.size.width - 80, height: 100))
                imageView.image = #imageLiteral(resourceName: "google_logo")// google logo image
                imageView.contentMode = UIViewContentMode.scaleAspectFit        
                footerView.addSubview(imageView)            
                return footerView
            }
            else
            {
                return nil
            }
        }
    

    请注意,您还必须设置页脚视图高度:

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
        {
            if(section == tableView.numberOfSections - 1)
            {
                return 100
            }
            else
            {
                return 0.001
            }
        }