繁体   English   中英

文字大小无法在UICollectionViewCell中调整

[英]Text size not adjusting in UICollectionViewCell

我正在尝试在单元格中填充某些文本。

在此处输入图片说明

目前,即使我设置了以下属性,我仍然看到类似上面的内容:

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell : mainCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! mainCell
    cell.backgroundColor = cellColor[indexPath.row]
    cell.cellLabel.text = cellLabels[indexPath.row]

    cell.cellLabel.font = cell.cellLabel.font.withSize(27)
    cell.cellLabel.adjustsFontSizeToFitWidth = true
    cell.cellLabel.minimumScaleFactor = 0.1
    cell.cellLabel.baselineAdjustment = .alignCenters
    cell.cellLabel.textAlignment = .center
    cell.cellLabel.lineBreakMode = .byWordWrapping
    cell.cellLabel.numberOfLines = 4
}

我也尝试了从属性检查器执行的操作,但似乎代码覆盖了通过属性检查器进行的设置。

我想要的是减少字体并包装单词(如果需要),但适合整个单元格。

您应将cellLabel顶部,底部,前导和尾随约束设置为“单元格视图”。 然后只有它适合单元格视图。

如果要居中,则至少设置前导和尾随

请指定标签约束为:

  1. 导致单元格视图
  2. 尾随cellview
  3. 顶部到单元格视图
  4. 从底部到单元格视图
  5. 更改行数= 0(它将自动包装内容并在另一行显示)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM