【问题标题】:How do I make the area on the top of a UISearchBar (when on a UITableView) in iOS 7 transparent?如何使 iOS 7 中 UISearchBar 顶部的区域(在 UITableView 上时)透明?
【发布时间】:2014-03-08 03:26:27
【问题描述】:
这是描述问题的图片。请注意,UISearchBar 上方的区域没有其下方的背景。我不想要灰色,我想要拉下UITableView 时的深栗色背景。
我所知道的一切都设置为[UIColor clearColor],包括视图背景等。它在 iOS 6 中可以正常工作,但在 iOS 7 中不行!
我还附上了一个示例项目,以便有人可以看看我在这里做错了什么?
Click here to download my sample project
也许我只是错过了一些愚蠢的东西?
谢谢!
【问题讨论】:
标签:
ios
objective-c
xcode
cocoa-touch
uitableview
【解决方案1】:
您可以做两件事:1) 向 UITableView 添加一个明确的清晰背景视图。或者,2) 将您的 UIImageView 设置为 UITableView 的背景视图。
这些工作中的任何一个。这是使您的示例工作的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
backgroundImageView.image = [UIImage imageNamed:@"Film_bg.png"];
[self.view addSubview:backgroundImageView];
[self.view sendSubviewToBack:backgroundImageView];
// solution 1
// self.tableView.backgroundView = [UIView new];
// self.tableView.backgroundView.backgroundColor = [UIColor clearColor];
// solution 2
self.tableView.backgroundView = backgroundImageView;
}