ios - 在滚动表格视图时,标签的角半径变得扭曲
问题描述
我有一个标签,根据某些条件,某些行可以看到该标签。我在堆栈视图中添加了标签。标签的 UI 是背景颜色和圆角半径为圆形。
我有子类 UItableview 单元格并使用了以下代码:
class SampleCell: UITableViewCell {
@IBOutlet weak var status: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func prepareForReuse() {
super.prepareForReuse()
self.status.text = nil
}
override func didMoveToSuperview() {
super.didMoveToSuperview()
layoutIfNeeded()
}
func setUpStatusLabel(isShow: Bool) {
self.status.text = "Status"
self.status.textColor = UIColor.red
self.status.font = UIFont.systemFont(ofSize: 11)
self.status.layer.cornerRadius =
self.status.frame.size.height/2
self.status.layer.masksToBounds = false
self.status.layer.backgroundColor = UIColor.lightGray.cgColor
self.status.isHidden = !isShow
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = (tableView.dequeueReusableCell(withIdentifier: "sample", for: indexPath) as? SampleCell)!
if indexPath.row % 2 == 0 {
cell.setUpStatusLabel(isShow: true)
} else {
cell.setUpStatusLabel(isShow: false)
}
}
当我启动此代码并滚动表格视图时,标签的角半径有时会变成显示矩形视图,这意味着没有角半径,有时背景颜色也会丢失。当用户滚动表格视图时,我需要保留所有这些。
解决方案
在 cellForRowAt indexPath cell.selectionStyle = .none 试试这个
推荐阅读
- python - Python中的公平硬币
- python - 模块 scipy 没有属性 __version__
- apache-spark - SparkException:作业因阶段失败而中止。引起:java.lang.ArrayIndexOutOfBoundsException
- python - 使用多元时间序列预测的需求预测
- python - ModuleNotFoundError:没有名为“couchbase.cluster”的模块;'couchbase' 不是一个包
- c++ - 我正在尝试从源代码为 conda 安装 cudf,我无法使用 cmake 安装它
- java - Springboot [2.1.6.RELEASE] - 禁用自动更正输入日期
- python - 自定义模型方法上的 Django order_by
- python - 我正在尝试在熊猫的数据框中切片一列
- c# - 程序集加载问题(“无法加载类型”)