Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change UISearchBar from round to rectangle?

i will like to know how do i need to change a UISearchBar from the default round curve to a rectangle.

enter image description here

enter image description here

like image 870
Desmond Avatar asked Nov 04 '11 07:11

Desmond


1 Answers

    for (UIView *searchBarSubview in [mySearchBar subviews]) {
        if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
            @try {

                [(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleRoundedRect];
            }
            @catch (NSException * e) {
                // ignore exception
            }
        }
    }

Swift 4:

mySearchBar.subviews().forEach { searchBarSubview in
  if searchBarSubview is UITextInputTraits {
    do {
        (searchBarSubview as? UITextField)?.borderStyle = .roundedRect
    } catch {
        // ignore exception
    }
  }
}
like image 131
Keller Avatar answered Oct 21 '22 04:10

Keller