【发布时间】:2019-01-28 06:38:00
【问题描述】:
我正在更改UILabel 的颜色和UITableView 中可重复使用原型单元格中的文本。对于一个特定的单元格(我从数据库中获取信息的单元格),文本变得扭曲和像素化。我怀疑这与多次加载表格单元格有关。这是我调用要显示的单元格的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let event = events[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "eventCell") as! eventCell
cell.setEvent(event: event)
return cell
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
//This code right here is mostly just for rounded edges but maybe the issue is here?
let verticalPadding: CGFloat = 15
let maskLayer = CALayer()
maskLayer.cornerRadius = 10
maskLayer.backgroundColor = UIColor.black.cgColor
maskLayer.frame = CGRect(x: cell.bounds.origin.x, y: cell.bounds.origin.y, width: cell.bounds.width, height: cell.bounds.height).insetBy(dx: 0, dy: verticalPadding/2)
cell.layer.mask = maskLayer
}
然后是eventCell 类中的代码,其中包含如何显示代码的所有说明:
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
// and a few more outlets
func setEvent(event: event) {
dateLabel.text = event.date
titleLabel.text = event.title
//and a few more of those^^ you get the idea
db.collection("events").document(event.docID).getDocument { (document, error) in
if let document = document, document.exists {
let chairArray = document.data()!["chairPeople"] as! Array<String>
for person in chairArray {
if (person == event.email) {
self.eventInfoButton.backgroundColor = UIColor(white: 50, alpha: 1)
self.dateLabel.textColor = UIColor(white: 50, alpha: 1)
self.titleLabel.textColor = UIColor(white: 50, alpha: 1)
self.descriptionLabel.textColor = UIColor(white: 50, alpha: 1)
self.eventInfoButton.setTitle("Chairsperson tools", for: .normal)
self.contentView.backgroundColor = UIColor(red:0.26, green:0.55, blue:0.79, alpha:1.0)
}
}
}
}
// This code right here ^^ grabs from the database and modifies the look if a conditon is met. If the condition is met, the text becomes distorted
}
【问题讨论】:
标签: ios swift uitableview uikit uilabel