2017-07-04 9 views
1

検索バーの境界を丸い角に変更する方法。私のコードは以下の通りで、オレンジ色の境界線が尖った四角形ではなく丸められる必要があります。検索バーの丸い角を

// Search bar 
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 60, 270, 41)]; 
self.searchBar.delegate = self; 
self.searchBar.placeholder = MEGLocalizedString(@"search_hint_home_screen", nil); 
UIColor *searchBarBackgroundColor = [UIColor clearColor]; 
self.searchBar.backgroundImage = [UIImage imageFromColor:searchBarBackgroundColor]; 
[self.searchBar setImage:[[UIImage imageNamed:@"search_icon_general.png"] imageTintedWithColor:primaryEventColor] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal]; 
    UIView *textField = [self.searchBar subviewWithKindOfClass:[UITextField class]]; 
    textField.backgroundColor = [UIColor orangeColor]; 
//  textField.layer.borderWidth = 1; 
    textField.layer.cornerRadius = 14; 
    [(UITextField *)textField setBorderStyle:UITextBorderStyleNone]; 
    // Change the search bar placeholder text color 
    [textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; 
} 
self.searchBar.layer.cornerRadius = 14; 
self.searchBar.layer.borderColor = [UIColor orangeColor].CGColor; 

enter image description here

+1

試してみてください。 self.searchBar.layer.masksToBounds =真 self.searchBar.clipsToBounds =真 – ninjaproger

答えて

1

は、この問題を解決してください

textField.layer.masksToBounds = true