ios - UILabel 不显示整个文本
问题描述
我有一个集合视图单元格,它有一个按钮和一个标签。因此,每当我在集合视图上添加项目时,都会显示多对按钮和标签,即 button1-label1,然后在 label1 和 button2 之间有一些空格后显示 button2-label2。
每当我为标签分配一些文本时,它只会显示标签上文本的前 2 个字母。我尝试增加标签的宽度,在标签上设置文本后调用“sizeToFit()”和“layoutIfNeeded()”,但仍然没有任何变化。
我究竟做错了什么?
标签框架是- (34.0, 10.0, 100.0, 16.0)
集合视图布局 API:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 100
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 100
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 25)
}
以下是标签设置:
解决方案
我花了一些时间检查所有内容的 frame.width 值,并注意到即使标签的 frame 更大,实际集合视图单元格的 frame.width 也小于标签的 frame.width。以下是解决方案:
collectionViewCell.frame.size.width = collectionViewCell.label.frame.width + collectionViewCell.button.frame.width + 25
上述解决方案中的 25 代表“minimumInteritemSpacingForSectionAt”,我将其从 100 更改为 25。
推荐阅读
- php - Laravel 登录后重定向
- git - 执行 git 命令 git pull --allow-unrelated-histories 后无法退出打开的文件
- javascript - urql useQuery 的暂停选项不会暂时冻结请求
- javascript - 交换图像文件并将css类添加到使用JS滚动时的img标签
- python - 如何在Python中找到给定日期期间每个季度的最后一天?
- confluent-platform - Confluent Kafka - Windows 上的模式注册表
- asp.net-core - 在 ASP.NET Core 中,什么类用于模型验证错误响应?
- c# - 是否可以将 MahApps 的 TextBoxHelper 应用于 ScrollViewer?
- android - 如何在用户单击 Android 上的按钮时读取 NFC 标签
- laravel - 无法弄清楚连接