how to change UISearchBar from round to rectangle?

后端 未结 12 1548
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 01:54

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

\"enter

12条回答
  •  野性不改
    2021-02-09 02:11

        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
        }
      }
    }
    

提交回复
热议问题