简体   繁体   English

如何在iOS 7中使UISearchBar顶部的区域(在UITableView上)透明?

[英]How do I make the area on the top of a UISearchBar (when on a UITableView) in iOS 7 transparent?

Here is a picture describing the problem. 这是描述问题的图片。 Notice that the area above the UISearchBar does not have the background as below it. 请注意, UISearchBar上方的区域没有下面的背景。 I don't want the gray color, I want the dark maroon background when pulling down on the UITableView . 我不希望使用灰色,而是当按下UITableView时希望使用深褐红色的背景。

Everything I know of is set to [UIColor clearColor] , including backgrounds of views, etc. It works fine in iOS 6 but not iOS 7! 我所知道的一切都设置为[UIColor clearColor] ,包括视图背景等。 它在iOS 6中可以正常工作,但在iOS 7中却不能正常工作!

I've also attached a sample project so someone can take a look and see what I am doing wrong here? 我还附加了一个示例项目,以便有人可以看一眼,看看我在这里做错了什么?

Click here to download my sample project 单击此处下载我的示例项目

Maybe I am just missing something stupid? 也许我只是想念一些愚蠢的东西?

Thanks! 谢谢!

在此处输入图片说明

Two things you could do: 1) add an explicit clear background view to the UITableView. 您可以做两件事:1)向UITableView添加一个明确的透明背景视图。 Or, 2) set your UIImageView to be the background view of the UITableView. 或者,2)将您的UIImageView设置为UITableView的背景视图。

Either of these work. 这些工作之一。 Here's the code that makes your sample work: 这是使您的示例工作的代码:

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM