我正在尝试自定义UISegmented控件的字体,我使用以下代码,如下所示:
let selectedfont = UIFont(name:"Roboto-Bold", size:22)
let unselectedfont = UIFont(name:"Roboto-Regular", size:22)
let normalTextAttributes: [String: Any] = [
NSForegroundColorAttributeName: UIColor(red: 0.60, green: 0.60, blue: 0.60, alpha: 1.0),
NSFontAttributeName: unselectedfont as Any
]
let selectedTextAttributes: [String: Any] = [
NSForegroundColorAttributeName: UIColor.black,
NSFontAttributeName: selectedfont as Any
]
self.setTitleTextAttributes(normalTextAttributes, for: UIControlState())
self.setTitleTextAttributes(selectedTextAttributes, for: .highlighted)
self.setTitleTextAttributes(selectedTextAttributes, for: .selected)
但应用程序崩溃显示: 由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' - [NSNull pointSize]:无法识别的选择器
这是什么问题?任何帮助都会得到满足。
答案 0 :(得分:10)
您对UIFont(name:,size:)
的来电可能会返回nil
。
您是否添加了自定义字体properly?
font.ttf