Hamish Rickerby

Technology Consultant & iOS Developer based in Sydney, Australia

UISearchBar’s UITextField

| Comments

For an update that I’m making to Moving Van (you should buy it now!) I need to customise the font that is displayed in a UISearchBar’s text field. The search bar does not actually expose it’s UITextField property, but because the search bar is a UIView, it’s trivial to access the field to allow customisation.

for (UIView *searchSubview in mySearchBar.subviews) {
  if ([searchSubview isKindOfClass:[UITextField class]]) {
    // Do your text field customisation in here
    [(UITextField *)searchSubview setTextColor:[UIColor redColor]];
  }
}

HTH.

Comments