gpt4 book ai didi

ios - 如果 tableview 为空,则显示标签和图像

转载 作者:行者123 更新时间:2023-11-28 06:30:39 25 4
gpt4 key购买 nike

我在 tableView 为空时创建了解决方案,然后显示标签“无可用数据”,否则显示内容。但是我无法同时显示背景图像和标签。我做错了什么?

我是这样做的:

var numOfSections: Int = 0
if reviewsArray.count != 0{

tableView.separatorStyle = .singleLine
numOfSections = reviewsArray.count

}
else{
let noDataLabel: UILabel = UILabel(frame: CGRect(0, 0, tableView.bounds.size.width, tableView.bounds.size.height))
noDataLabel.text = "No data available"
noDataLabel.textColor = UIColor.black
noDataLabel.textAlignment = .center
tableView.backgroundView = noDataLabel
tableView.separatorStyle = .none

}

然后在 viewDidLoad 中我添加了模糊的背景图片:

let blurredBackgroundView = BlurredBackgroundView(frame: .zero)
tableView.backgroundView = blurredBackgroundView
tableView.separatorEffect = UIVibrancyEffect(blurEffect: blurredBackgroundView.blurView.effect as! UIBlurEffect)

请不要推荐任何第三方库 :)

最佳答案

您正在将背景 View 设置为 blurredBackgroundView,然后设置为 noDataLabel。通过将其设置为 noDataLabel,您将摆脱 blurredBackgroundView。

我会尝试添加 noDataLabel 作为背景 View 的 subview 。喜欢:

tableView.backgroundView.addSubview(noDataLabel)

关于ios - 如果 tableview 为空,则显示标签和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40467807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com