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

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

本文介绍了如何将UISearchBar从圆形更改为矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

这篇关于如何将UISearchBar从圆形更改为矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:22