I also recently achieved this in a project by going through the areas of the UISearchBar object. However, the text box was not an immediate child, as the accepted answer suggested, but a peek at another peep. At some point, the hierarchy of the internal appearance was probably changed. (SDK 8.4)
+ (void)setSearchBar:(UISearchBar *)searchBar cornerRadius:(CGFloat)radius { //set searchbar corner radius for(UIView *possibleSearchBarTextFieldSuperview in [searchBar subviews]) { if([[possibleSearchBarTextFieldSuperview subviews] count] > 0) { for(UIView *possibleInnerSearchBarTextField in [possibleSearchBarTextFieldSuperview subviews]) { if([possibleInnerSearchBarTextField conformsToProtocol:@protocol(UITextInputTraits)]) { possibleInnerSearchBarTextField.layer.cornerRadius = radius; possibleInnerSearchBarTextField.layer.masksToBounds = YES; return; } } } } }
This method does not use undocumented methods, so it is probably safe on the App Store, although it may stop working with future changes in the SDK.
Şafak Gezer
source share