ios - UISearchBar 背景外观

标签 ios iphone uisearchbar

我希望我的搜索栏看起来像这样:

enter image description here

这就是我创建搜索栏的方式:

    search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 308, 27)];
    search.delegate = self;
    search.center = CGPointMake(self.frame.size.width/2, 10 +search.frameHeight/2);
    search.placeholder = NSLocalizedString(@"search foods you like or dislike", nil);
    search.backgroundImage = nil;
    search.backgroundColor = [UIColor clearColor];

但这就是我得到的:

enter image description here

我做错了什么?我如何去除 textField 两侧多余的灰色边缘?

最佳答案

您可以使用以下代码实现:

search.barTintColor = [UIColor clearColor];

关于ios - UISearchBar 背景外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20998134/

相关文章:

ios - iOS音频仅输出到耳机插孔

ios - CLLocationManager.authorizationStatus 导致 EXC_BAD_ACCESS code=2

ios - Xcode 11 beta 中的 "Preview Assets" Assets 目录有什么用?

ios - 搜索使应用程序崩溃后重新加载 View

ios - iOS中弹出窗口的新 View Controller 或同一 View Controller 中的新 View

iphone - 在 iOS 应用程序中加入自定义单词词典

iphone - 在运行 iOS 时,以编程方式即时更改语言

ios - 如何在 View Controller 上获取导航栏?

ios - 在 objective-c UISearchBar 图标中想要显示在左边

ios - 我的 UISearchBar 移动到顶部(动画)--> 想要禁用