gpt4 book ai didi

ios - 创建一个清晰的 UISearchBar

转载 作者:行者123 更新时间:2023-11-28 22:10:33 24 4
gpt4 key购买 nike

我需要一个 uisearchbar 来清楚

我已经尝试了所有建议的方法 - 将背景图像设置为清晰的等。

但是 - UISearchbar 似乎总是有一个框架 - 可以设置(使用图像方法)和一个带有色调的覆盖层(这是从搜索栏边界插入的搜索栏部分),它总是具有相同的高度和黑色调 -

我无法使用任何搜索栏或工具栏方法摆脱这种色调 - 是否有黑客可以使这一点变得清晰 - 或者将其拉伸(stretch)到 UISearchbar 的所有角落???

这是我正在尝试的最后一个化身的片段 - 没有运气:(

self.searchBar = [[UISearchBar alloc] initWithFrame:searchBarBackground.bounds];
self.searchBar.placeholder = NSLocalizedString(@"Search", nil);
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[searchBarBackground addSubview:self.searchBar];
self.searchBar.translucent = YES;
self.searchBar.backgroundImage = [UIImage new];
self.searchBar.scopeBarBackgroundImage = [UIImage new];

添加搜索栏的层次结构转储

 <UISearchBar: 0x17f36340; frame = (0 0; 240 44); text = ''; opaque = NO; gestureRecognizers = <NSArray: 0x17f35e00>; layer = <CALayer: 0x17f36270>>
| <UIView: 0x17f36010; frame = (0 0; 240 44); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x17f35fe0>>
| | <UISearchBarBackground: 0x17f35bc0; frame = (0 0; 240 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x17f35ac0>>
| | | <_UIBackdropView: 0x17f317d0; frame = (0 0; 240 44); hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <_UIBackdropViewLayer: 0x17f311e0>>
| | <UISearchBarTextField: 0x17f34e40; frame = (0 0; 0 0); text = ''; clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x17f34e10>>
| | | <_UISearchBarSearchFieldBackgroundView: 0x17f337c0; frame = (0 0; 0 0); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x17f33900>>
| | | | <_UISearchBarSearchFieldBackgroundView: 0x17f32540; frame = (0 0; 0 0); hidden = YES; opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x17f32480>>
| | | | <_UISearchBarSearchFieldBackgroundView: 0x17f31e00; frame = (0 0; 0 0); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x17f31ea0>>


*

/

最佳答案

将我的 UISearchbar 的背景设置为“white with alpha”这样微不足道的事情真令人头疼! - 这就是我最终能够创建我想要的外观的方式。白色背景上的“清晰”UISearchbar

self.searchBar = [[UISearchBar alloc] initWithFrame:SearchBarFrame];
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
UIView *whiteView = [[UIView alloc] initWithFrame:self.searchBar.bounds];
whiteView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
whiteView.layer.cornerRadius = 5;

[self.searchBar insertSubview:whiteView atIndex:0];

self.searchBar.placeholder = NSLocalizedString(@"Search", nil);
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[self addSubview:self.searchBar];
self.searchBar.translucent = YES;
self.searchBar.backgroundImage = [UIImage new];
self.searchBar.scopeBarBackgroundImage = [UIImage new];
UIImage *clearImage = [UIImage imageWithColor:[UIColor clearColor] andSize:SearchBarFrame.size];
[self.searchBar setSearchFieldBackgroundImage:clearImage forState:UIControlStateNormal];

还有辅助方法

+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
rect.size = size;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

关于ios - 创建一个清晰的 UISearchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23041811/

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