尝试使用NSAttributedString更改pickerView中的字体:
public func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
guard let castDict = self.castDict else {
return nil
}
let name = [String](castDict.keys)[row]
switch component {
case 0:
return NSAttributedString(string: name, attributes: [NSForegroundColorAttributeName : AppColors.Rose.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
case 1:
guard let character = castDict[name] else {
return NSAttributedString(string: "Not found character for \(name)", attributes: [NSForegroundColorAttributeName : AppColors.Rose.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
}
return NSAttributedString(string: character, attributes: [NSForegroundColorAttributeName : AppColors.LightBlue.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
default:
return nil
}
}颜色已更改,字体-不是:

我做错了什么?
https://stackoverflow.com/questions/41197788
复制相似问题