【问题标题】:Search bar rounded corner搜索栏圆角
【发布时间】:2017-07-05 05:47:10
【问题描述】:

如何将搜索栏的边框改为圆角。下面是我的代码,我需要将橙色边框四舍五入而不是尖锐的矩形。请帮忙

// 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;

【问题讨论】:

  • 试试:self.searchBar.layer.masksToBounds = true self.searchBar.clipsToBounds = true

标签: objective-c uitextfield uisearchbar rounded-corners


【解决方案1】:

这解决了你的问题

textField.layer.masksToBounds = true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-14
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多