gpt4 book ai didi

ios - 如何在 IOS 中实现纯搜索栏

转载 作者:行者123 更新时间:2023-11-29 03:34:27 25 4
gpt4 key购买 nike

我想删除默认搜索栏的边框并实现普通搜索栏。见下图

默认搜索栏,

Default Search Bar

这就是我想要实现的目标

Plain Search bar

我用谷歌搜索并尝试了下面的代码,但没有达到预期的效果,

for (id img in searchbar.subviews) 
{
if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[img removeFromSuperview];
}
}

searchbar.delegate = self;
searchbar.layer.borderWidth = 0;
searchbar.layer.borderColor = [[UIColor clearColor] CGColor];

我该如何实现这个?

最佳答案

感谢您的回答。我已经使用下面的代码解决了我的问题......

Plain White Search bar background image used in the below code

UITextField *txfSearchField = [self.searchbar valueForKey:@"_searchField"];
[txfSearchField setBackgroundColor:[UIColor whiteColor]];
[txfSearchField setLeftViewMode:UITextFieldViewModeNever];
[txfSearchField setRightViewMode:UITextFieldViewModeNever];
[txfSearchField setBackground:[UIImage imageNamed:@"searchbar_bgImg.png"]];
[txfSearchField setBorderStyle:UITextBorderStyleNone];
//txfSearchField.layer.borderWidth = 8.0f;
//txfSearchField.layer.cornerRadius = 10.0f;
txfSearchField.layer.borderColor = [UIColor clearColor].CGColor;
txfSearchField.clearButtonMode=UITextFieldViewModeNever;

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldItalicMT" size:20]];
[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blackColor]];

关于ios - 如何在 IOS 中实现纯搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com