gpt4 book ai didi

iphone - 如何为UISearchBar着色,使其与背景无缝融合

转载 作者:行者123 更新时间:2023-12-01 19:15:41 24 4
gpt4 key购买 nike

我正在尝试给此UISearchBar着色,以使其与背景看起来无缝(如第二幅图像所示)。是否有可能做到这一点?我已经尝试以编程方式在IB中设置,但是没有运气。

谢谢你的帮助

这是所需的外观:

最佳答案

   UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
[searchField setBackground:[UIImage imageNamed:@"searchfield_bg"]];

[self.searchBar setTintColor:[UIColor blackColor]];
UIImage *searchimg = [UIImage imageNamed:@"search_panel.png"];

for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:searchimg];
[self.searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
[bg release];
break;
}
}

我正在使用这些图像,您也可以使用并更改颜色,我的要求是制作一个黑色的搜索栏,以便我使用黑色


它看起来像:

关于iphone - 如何为UISearchBar着色,使其与背景无缝融合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511574/

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