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]];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 表情是什么,我认为表情就是表现出来的情绪。表情可以传达很多信息。高兴了当然就笑了,难过就哭了。两者是相互影响密不可...
    Persistenc_6aea阅读 126,866评论 2 7
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 11,277评论 0 4