I am trying to customize the font of the UISegmented control and i am using the following code as shown below:
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)
But the application crashes showing this: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull pointSize]: unrecognized selector
What is the issue here? Any help will be appriciated.
Your call to UIFont(name:,size:)
is likely returning nil
.
Did you add the custom font properly?
font.ttf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With