[NSNull pointSize]: unrecognized selector sent to instance in swift3 while using custom fonts

Viewed 2711

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.

1 Answers
Related