Set rounded corners and border to background(Not the UITextField) of UISearchBar in ios7

StackOverflow https://stackoverflow.com/questions/22807074

Вопрос

How can i apply rounded corners and a border to the background of UISearchBar in ios7? I am able to change the background color of the bar.

Something like this

enter image description here

Thanks

Это было полезно?

Решение

  UISearchBar *searchBar  = [[UISearchBar alloc] init];
  searchBar.layer.cornerRadius  = 6;
  searchBar.clipsToBounds       = YES;
  [searchBar.layer setBorderWidth:1.0];
  [searchBar.layer setBorderColor:[[UIColor lightGrayColor].CGColor];

Другие советы

For making the search bar round rect use this:

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

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

For changing background color use this:

yourSearchBar.barTintColor = [UIColor redColor]; // Use you necessary color.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top