gpt4 book ai didi

ios - UISearchBar 上方的线

转载 作者:可可西里 更新时间:2023-11-01 05:02:02 25 4
gpt4 key购买 nike

很长一段时间以来,我一直试图删除我的 UISearchBar 上方的有害行,但没有成功。它在浅色背景上显得很暗,在深色背景上显得很亮:

enter image description here enter image description here

我看了this question ,但它与分隔符或下拉刷新无关。当我最终决定放弃并寻求帮助时,我又开始四处寻找并找到了一个非常简单(虽然可能不完全直观)的解决方案,所以我想我会分享它以防其他人面临同样的问题。我按如下方式配置搜索栏:

// I tried this drawing method
[self.searchBar setBackgroundImage:[[UIImage imageNamed:@"linen_bg_bar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];
// and this one.
[self.searchBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"linen_bg_bar.png"]]];
// Same problem either way.

[self.searchBar setPlaceholder:NSLocalizedString(@"Filter", @"placeholder text in the search bar")];
[self.searchBar setSearchFieldBackgroundImage:[[UIImage imageNamed:@"linen_textfield_search.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(16, 16, 16, 16)] forState:UIControlStateNormal];
[self.searchBar setImage:[UIImage imageNamed:@"linen_icon_search.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
self.table.tableHeaderView = self.searchBar;
[self.table setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"linen_bg_dark.png"]]];

根据 this post's建议,我尝试在它上面绘图,但似乎绘图仍然在线下渲染。

CGRect rect = self.searchBar.frame;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, 2)];
lineView.backgroundColor = [UIColor redColor];

请参阅带有红色“掩盖”线的示例:

enter image description here

最佳答案

我不确定确定这会起作用,但它是有道理的,因为必须为覆盖 View 设置一个 y 值。

searchBar.clipsToBounds = YES;

关于ios - UISearchBar 上方的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15370070/

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