如何将UISearchBar从圆形更改为矩形?

Des*_*ond 8 iphone uisearchbar ios

我想知道如何将UISearchBar从默认的圆形曲线更改为矩形.

在此输入图像描述

在此输入图像描述

Kel*_*ler 19

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

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

斯威夫特4:

mySearchBar.subviews().forEach { searchBarSubview in
  if searchBarSubview is UITextInputTraits {
    do {
        (searchBarSubview as? UITextField)?.borderStyle = .roundedRect
    } catch {
        // ignore exception
    }
  }
}
Run Code Online (Sandbox Code Playgroud)