到目前为止,我有:
var imageView = UIImageView(frame: CGRectMake(10, 10, cell.frame.width - 10, cell.frame.height - 10))
let image = UIImage(named: ImageNames[indexPath.row])
imageView.image = image
cell.backgroundView = imageView
这设置了背景图像,但我的目标是在任一侧有10个像素的填充。这只是用这张图片填充单元格的背景。
答案 0 :(得分:15)
我实际上能够解决自己的问题。我刚刚创建了背景视图,然后像这样添加了一个子视图:
let imageView = UIImageView(frame: CGRectMake(10, 10, cell.frame.width - 10, cell.frame.height - 10))
let image = UIImage(named: "Image Name")
imageView.image = image
cell.backgroundView = UIView()
cell.backgroundView!.addSubview(imageView)
这可以防止任何事情被遮盖并达到我想要的效果。
答案 1 :(得分:0)
使用
var imageView = UIImageView(frame: CGRectMake(10, 10, cell.frame.width - 10, cell.frame.height - 10))
let image = UIImage(named: ImageNames[indexPath.row])
imageView.image = image
//Just add imageView as subview of cell
cell.addSubView(imageView)
cell.sendSubviewToBack(imageView)