Nik*_*nou 3 uitableview ios swift
我正在尝试将 UITableView 的附件视图设置为 UILabel。我尝试在互联网上寻找答案,但找不到任何东西。这是我所做的:
let listCountLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
label.text = "1"
label.layer.borderWidth = 2
label.layer.borderColor = UIColor.lightGray.cgColor
label.textColor = .lightGray
label.layer.cornerRadius = label.frame.height / 2
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont(name: "HelveticaNeue", size: 14)
label.textAlignment = .center
return label
}()
//Add to Subview
view.addSubview(listCountLabel)
cell.accessoryView = listCountLabel
Run Code Online (Sandbox Code Playgroud)
不需要调用view.addSubView()。只需在将其插入 cell.accessoryView 之前调用 listCountLabel.sizeToFit() 即可。
listCountLabel.sizeToFit()
cell.accessoryView = listCountLabel
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1151 次 |
| 最近记录: |