For Swift 4.2+
let defaultTextAttributes = [
NSAttributedString.Key.font: UIFont.init(name: "Ubuntu-Regular", size: 16),
NSAttributedString.Key.foregroundColor: UIColor.gray
]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = defaultTextAttributes