Remove Border of UISearchBar in iOS7

前端 未结 10 1676
死守一世寂寞
死守一世寂寞 2020-12-24 10:46

I\'m trying to remove border of UISearchBar in iOS 7. In iOS 6 it\'s working fine. I created the UISearchBar programatically. I tried almost every thing from Stack Overflow

10条回答
  •  心在旅途
    2020-12-24 11:17

    self.searchBar.translucent = NO;
    self.searchBar.opaque = NO;
    if ([self.searchBar respondsToSelector:@selector(setSearchBarStyle:)]) {
        self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
    }
    
    // iOS 7 remove 1 px bottom border
    if ([self.searchBar respondsToSelector:@selector(setBarTintColor:)]) {
        self.searchBar.barTintColor = [UIColor clearColor];
    }
    self.searchBar.barStyle = UIBarStyleDefault;
    
    // to remove the 1px bottom border iOS 5, 6
    [self.searchBar setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor] andSize:CGSizeMake(1.0f, 1.0f)]];
    

    The order of code seems does matter. It doesn't work if I set the barStyle before the searchBarStyle.

提交回复
热议问题