【发布时间】:2017-06-13 12:24:39
【问题描述】:
我查看了很多答案,但要么只是 UILabel 要么 UIImage 不是两者兼而有之。所以在尝试实现它之后,我终于发现我们不能做两个tableView.backgroundView。这是我到目前为止所做的:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let noDataLabel: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: tableView.bounds.size.height))
let image = UIImage(named: "noData")
let noDataImage = UIImageView(image: image)
noDataImage.frame = CGRect(x: 0, y: 10, width: 20, height: 20)
if allData.count == 0 {
noDataLabel.isHidden = false
noDataImage.isHidden = false
noDataLabel.text = "No data added. Add new entry \nby pressing the add icon on top right."
noDataLabel.textColor = UIColor.black
noDataLabel.numberOfLines = 3
noDataLabel.backgroundColor = UIColor.white
noDataLabel.textAlignment = .center
//what to do from here
tableView.backgroundView = noDataImage
tableView.backgroundView = noDataLabel
//end
tableView.separatorStyle = .none
return 0;
}
else {
noDataLabel.backgroundColor = UIColor.clear
noDataLabel.isHidden = true
noDataImage.isHidden = true
tableView.backgroundView = nil
return allData.count
}
我想显示一张图片,在该图片下方我想显示UILabel。我怎样才能做到这一点?
【问题讨论】:
-
我会将 tableView 放在“无数据”视图上方,并使 tableViews 背景透明。
-
你的意思是在 UIView 上我应该添加图像和标签,如果计数为零,那么我应该让表格的背景透明?
-
创建一个视图而不是分配给背景视图,下面的@arpit 已经回答了这个问题
标签: ios uitableview swift3 uiimage