表格单元中的UILabel属性标签不保留在情节提要中分配的属性

时间:2019-03-13 23:26:40

标签: ios swift uitableview uilabel nsattributedstring

我在表格单元格中添加了UILabel,并在情节提要中为其分配了自定义字体,粗细和颜色。在cellForRowAt中,当我更改标签的值时,它不会保留在情节提要中分配的标签属性。

为什么它不能在表单元格中工作,而如果不能在表单元格中工作,则为什么其他工作呢?

// this doesn't preserve attributes for name assigned in storyboard
cell.name.text = "Name"

要使其正常工作,我必须构造属性字符串

cell.name.attributedText = NSAttributedString(string: "Name",
                                             attributes: [NSAttributedString.Key.font: MyFont, NSAttributedString.Key.foregroundColor: .white]

0 个答案:

没有答案