Ios 无法更改我的collectionView单元格的字体大小和颜色';s按钮
我用两个标签和两个按钮以编程方式填充CollectionView单元格。我已经研究了堆栈溢出的几种不同方法来更改按钮的标题字体大小和颜色,以及标签的文本颜色。这是我发现的大多数问题的解决方案,但仍然不起作用。非常感谢您的帮助!谢谢 我的标签代码:Ios 无法更改我的collectionView单元格的字体大小和颜色';s按钮,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我用两个标签和两个按钮以编程方式填充CollectionView单元格。我已经研究了堆栈溢出的几种不同方法来更改按钮的标题字体大小和颜色,以及标签的文本颜色。这是我发现的大多数问题的解决方案,但仍然不起作用。非常感谢您的帮助!谢谢 我的标签代码: let nameLabel: UILabel = { let label = UILabel() label.text = "name" label.font = label.font.withSize(13) labe
let nameLabel: UILabel = {
let label = UILabel()
label.text = "name"
label.font = label.font.withSize(13)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
我的按钮代码:
let kickButton: UIButton = {
let btn = UIButton()
btn.setTitle("Kick", for: .normal)
btn.titleLabel?.textColor = UIColor.black
btn.titleLabel?.font = UIFont(name: "System", size: 6)
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
创建新单元格的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "playerItem", for: indexPath) as! PlayerCollectionViewCell
cell.setupViews(parentSize: Int(self.playerCollectionView.frame.width))
print(self.playerArrayList[indexPath.item].userName)
cell.layer.cornerRadius = 6
cell.layer.borderWidth = 2
return cell
}
你能试试
UIFont.systemFont(大小:13)
看看它是否改变了字体吗?按钮的字体和颜色应该通过btn.setTitleColor(.red,for:.normal)
,btn.titleLabel?.font=UIFont.systemFont(大小:6)
来改变它的工作原理!谢谢@Ryan!