在UISearchBar中默认会呈现一个背景视图。怎样隐藏这个背景视图?我只需要 UISearchBar 中的搜索文本框部分。
if (([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] == NSOrderedAscending)) {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0.0);
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
searchBar.backgroundImage = blank;
searchBar.backgroundColor = [UIColor clearColor];
}
else {
searchBar.barTintColor = [UIColor clearColor];
}
Brandon的答案仍然可行,但要遵循Timothy Groote提到的条件。它就像是删除两个较低的子视图,并确保样式设置为半透明黑色(我在IB中这样做,但我认为在代码中这样做也可以)。
只是出于好奇,你们认为为什么这个解决方案不会被批准?该解决方案只使用公共API。