无法更改collectionView单元格按钮的字体大小和颜色

时间:2017-07-07 23:05:26

标签: ios swift uicollectionview uicollectionviewcell

我用两个标签和两个按钮以编程方式填充我的CollectionView单元格。我已经查看了堆栈溢出的几种不同的方法来更改标签的标题字体大小和颜色,以及标签的textcolor。这是我找到的大多数问题的解决方案,但它仍然无法正常工作。任何帮助是极大的赞赏!谢谢!

我的标签代码:

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
}

0 个答案:

没有答案