SWT SWT - 1 year ago 127
Objective-C Question

Change the font size and font style of UISearchBar iOS 7

How can I change the font size and font style of UISearchBar in iOS 7?

UITextField *textField = [[searchBar subviews] objectAtIndex:1];
[textField setFont:[UIFont fontWithName:@"Helvetica" size:20]];

Working in iOS 6 but it's getting crash in iOS 7

Answer Source

Try this, It's Working Fine for iOS 5.0 and up: (iOS 7 also)

- (void)viewDidLoad

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Helvetica" size:20]];


For iOS 8

- (void)viewDidLoad

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
            NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20],

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download