【发布时间】:2018-11-13 19:44:02
【问题描述】:
我有一个标签设置为属性字符串的 UICollectinViewCell。
在 cellForItem 中,我将一个简单的字符串转换为 NSAttributedString,这样我就可以设置 UILabel 的属性文本属性。
字符串"Attributed String Text" 仅在我滚动 CollectionView 时出现。如果我不滚动,"Label" 就会出现,因为这是在 IB 中设置的文本。如果我将 UILabel 保持为纯文本,则正确的文本会显示得很好。
// cellForItemAt
let string = "Attributed String Text"
let mutableAttributedString = NSAttributedString(string: string)
cell.subName.attributedText = mutableAttributedString
如何在不滚动 CollectionView 的情况下显示属性文本?
【问题讨论】:
-
你在哪里设置委托和数据源?
-
我在viewDidLoad中设置了delegate和dataSource。
-
你能发布完整的上下文
-
改用
cell.subName.text = "Something"。如果你没有看到任何东西,那与 NSAttributedString 无关,而是UICollectionView。但是我们需要更多上下文,cellForItemAt 的完整代码,重用问题? -
@Larme 谢谢,我会试试的。我也会从项目中发布更多代码。
标签: swift string uicollectionview uilabel nsattributedstring