如何在自定义单元格中为tableview设置旧金山字体



我有一个自定义单元格,用于添加了一些标签。对于此自定义单元格,我还为其创建了一个Swift文件。

说,我有以下标签:

标签
LabelAddress
labelzipcode

问题:如何为这些定制单元内的这些lable设置旧金山字体?在ViewController内部设置?

Example:
LabelShop.font = UIFont.systemFont(ofSize: 21.0 , weight: UIFontWeightSemibold)

请友好地扩展您的帮助。

谢谢

您可以从 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)在视图控制器中或直接从awakeFromNib中的单元本身。

此代码应该足够:label.font = UIFont.systemFont(ofSize: 21.0 , weight: UIFontWeightSemibold)

第一种方法:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell = tableView.dequeueReusableCell(withIdentifier: YOURCELLIDENTIFIER, for: indexPath)
   if let castedCell = cell as? YourCellClass {
       castedCell.label.font = UIFont.systemFont(ofSize: 21.0, weight: UIFontWeightSemibold)
   }
   return cell
}

第二:

override func awakeFromNib() {
   super.awakeFromNib()
   label.font = UIFont.systemFont(ofSize: 21.0 , weight: UIFontWeightSemibold)
}

最新更新