iOS开发 searchbar placeholder居中显示以及颜色问题

首先,UISearchBar Placeholder居中显示已经开源到gitee,目前已经适配到了iOS14。

去除UISearchBar背景颜色显示错误的问题代码如下:

        HsusueSearchBar *searchBar = [[HsusueSearchBar alloc] initWithFrame:CGRectZero];
        self.searchBar = searchBar;
        [self addSubview:searchBar];
        searchBar.placeholder = @"搜索用户名";
        searchBar.delegate = self;
//        searchBar.layer.borderWidth = 0.5;
//        searchBar.layer.borderColor = [IACColor(230, 230, 230) CGColor];
        searchBar.layer.masksToBounds = YES;
        searchBar.layer.cornerRadius = 3;
        //去除灰色背景
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 13.0) {
            for (UIView *view in self.searchBar.subviews) {
                // for later iOS7.0(include)
                if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
                    [[view.subviews objectAtIndex:0] removeFromSuperview];
                    break;
                }
                
            }
        }
        
        searchBar.backgroundColor = IACColor(240, 240, 240);
        searchBar.tintColor = [UIColor blackColor];//IACColor(240, 240, 240);
        [searchBar setBackgroundImage:[UIImage new]];

你可能感兴趣的:(iOS开发 searchbar placeholder居中显示以及颜色问题)