如果您使用的是静态表,世界上没有改变它的机会,你可能要采取这样的方法:
override func viewDidLoad() {
super.viewDidLoad()
//Create the UIImage
let image = UIImage(named: "testing")
//Create a container view that will take all of the tableView space and contain the imageView on top
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.width, height: self.view.bounds.height))
//Create the UIImageView that will be on top of our table
let imageView = UIImageView(frame: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.width, height: image!.size.height))
//Set the image
imageView.image = image
//Clips to bounds so the image doesnt go over the image size
imageView.clipsToBounds = true
//Scale aspect fill so the image doesn't break the aspect ratio to fill in the header (it will zoom)
imageView.contentMode = UIViewContentMode.ScaleAspectFit
containerView.addSubview(imageView)
self.tableView.backgroundView = containerView
}
使t他的细胞或标题透明,如你所愿。我不知道你的用户界面应该如何工作。此方法不会滚动imageView,但您可以简单地在scrollView委托方法中执行此操作。让我知道你是否需要它滚动,我会帮你出
看看tableView.backgroundView docs>背景视图将自动调整大小,以跟踪表视图的大小。这将作为所有单元格和页眉/页脚背后的表视图的子视图放置。某些设备的默认值可能不为零。 /// 如果您需要,您需要使用其他方法。可能是在桌子后面的imageView,并使表格背景颜色= clearColor() –
好吧,但我使用的是静态表格视图(在UItableviewcontroller中直接) – user3722523
问题,你想要背后的图像单元格或上面吗? –