For me, this worked using a recursive function to find the actual textfield.
extension UIView {
func recursive_applyTheme_Search(
#dynamicTextStyle: NSString,
bgColor: UIColor,
cursorColor: UIColor,
textColor: UIColor,
placeholderTextColor: UIColor,
borderColor: UIColor,
borderWidth: CGFloat,
cornerRadius: CGFloat) {
for subview in self.subviews
{
if subview is UITextField {
(subview as! UITextField).applyThemeForSearchBar(
dynamicTextStyle: dynamicTextStyle,
bgColor: bgColor,
cursorColor: cursorColor,
textColor: textColor,
placeholderTextColor: placeholderTextColor,
borderColor: borderColor,
borderWidth: borderWidth,
cornerRadius: cornerRadius)
}
else { subview.recursive_applyTheme_Search(
dynamicTextStyle: dynamicTextStyle,
bgColor: bgColor,
cursorColor: cursorColor,
textColor: textColor,
placeholderTextColor: placeholderTextColor,
borderColor: borderColor,
borderWidth: borderWidth,
cornerRadius: cornerRadius) }
}
}
}