我在表格单元格中添加了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]