首页 > 解决方案 > iPhone X UITableViewController 带有固定底栏显示不透明工具栏下方的表格内容

问题描述

我想制作一个带有固定底栏的 UITableViewController。所以我用这些代码做了这个。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    saveButton.size = CGSize(width: self.view.width, height: 50)
    saveButton.translatesAutoresizingMaskIntoConstraints = false
    saveButton.addTarget(self, action: #selector(saveContactsInfo), for: .touchUpInside)

    self.navigationController?.setToolbarHidden(false, animated: animated)
    let btn = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(saveContactsInfo))
    let fixspace = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
    fixspace.width = CGFloat.leastNormalMagnitude
    self.navigationController?.toolbar.items = [fixspace, btn, fixspace]

    self.navigationController?.toolbar.addSubview(saveButton)

 self.navigationController?.toolbar.leadingAnchor.constraint(equalTo: saveButton.leadingAnchor).isActive = true
    self.navigationController?.toolbar.trailingAnchor.constraint(equalTo: saveButton.trailingAnchor).isActive = true
    self.navigationController?.toolbar.topAnchor.constraint(equalTo: saveButton.topAnchor).isActive = true
    self.navigationController?.toolbar.bottomAnchor.constraint(equalTo: saveButton.bottomAnchor).isActive = true
    self.navigationController?.toolbar.clipsToBounds = true
    self.navigationController?.toolbar.barTintColor = UIColor.white
    self.navigationController?.toolbar.setBackgroundImage(UIImage(color: UIColor.white), forToolbarPosition: .bottom, barMetrics: .default)

}

底部栏显示如我所愿,但表格视图显示在底部栏下方。像这样:

在此处输入图像描述

我尝试取消选中 Under Bottom Bars,但效果不佳。

在此处输入图像描述

我只希望底部栏下方的区域是白色的。如何使这个显示正确?

标签: iosuitableviewuitoolbariphone-xsafearealayoutguide

解决方案


推荐阅读