How can I change the font size and font style of UISearchBar in iOS 7?
UITextField *textField = [[searchBar subviews] objectAtIndex:1];
[textField setFont:[U
For those looking for a working Swift version, I've adapted this answer. Swift doesn't currently support Objc varargs methods, so it doesn't work directly with the above methods. We can work around this by making an objective-c category that doesn't use varargs and calls what we need:
// UIAppearance+Swift.h
@interface UIView (UIViewAppearance_Swift)
// appearanceWhenContainedIn: is not available in Swift. This fixes that.
+ (instancetype)my_appearanceWhenContainedIn:(Class)containerClass;
@end
—
// UIAppearance+Swift.m
@implementation UIView (UIViewAppearance_Swift)
+ (instancetype)my_appearanceWhenContainedIn:(Class)containerClass {
return [self appearanceWhenContainedIn:containerClass, nil];
}
@end
Just be sure to #import "UIAppearance+Swift.h" in your bridging header.
Then just call:
UITextField.my_appearanceWhenContainedIn(UISearchBar.self).font = UIFont.systemFontOfSize(14.0)