当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to change the size of a UITableView background image?

问题描述:

How would i go about changing the size of a uitableview background image? By default it automatically sizes the image for me but i want mine a little smaller. I've tried doing the following...

let image = UIImage(named: "noFoldersImage")

let iv = UIImageView(image: image)

iv.contentMode = .scaleAspectFit

iv.layer.frame = CGRect(x: self.view.frame.midX, y: self.view.frame.midY, width: 200, height: 200)

self.tableView.backgroundView = iv

But it doesn't seem to work, any ideas? Thanks

网友答案:

You may change the implement like this:

    let image = UIImage(named: "noFoldersImage")
    let iv = UIImageView(image: image)
    iv.contentMode = .scaleAspectFit
    iv.layer.frame = CGRect(x: self.view.frame.midX, y: self.view.frame.midY, width: 200, height: 200)
    let tableViewBackgroundView = UIView()
    tableViewBackgroundView.addSubview(iv)
    self.tableView.backgroundView = tableViewBackgroundView
分享给朋友:
您可能感兴趣的文章:
随机阅读: