在iOS 6上不推荐使用groupTableViewBackgroundColor吗?

est*_*oza 36 background view tableview ios ios6

我只是用iOS 6.0和Xcode 4.5GM测试我的应用程序,我设置了这样的视图:

[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
Run Code Online (Sandbox Code Playgroud)

因此,视图具有与公共表视图相同的模式.

这适用于iOS 4和5,但在iOS 6中它只是给我一个白色背景.

这是否已被弃用?如果是这样,我该如何更换它?

谢谢

小智 31

在6.0种子程序期间将不推荐使用此方法如果您希望在自己的视图中具有类似于表视图背景的背景,则应创建一个空表视图并将其放在内容后面.

  • 有点丑陋的建议哈哈,你应该让设计师制作一个背景图像将是一个更好的解决方案.无论如何,由于不赞成提示而Upvote. (10认同)

3lv*_*vis 25

首先,将其添加到viewDidLoad:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBackground.png"]];
Run Code Online (Sandbox Code Playgroud)

要么

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBackground.png"]];
Run Code Online (Sandbox Code Playgroud)

然后将此图片添加到您的应用:

tableViewBackground.png

tableViewBackground.png

tableViewBackground@2x.png

tableViewBackground@2x.png


Fel*_*lix 18

我写了一个UIColor要替换的类别groupTableViewBackgroundColor:

@interface UIColor (UITableViewBackground)
+ (UIColor *)groupTableViewBackgroundColor;    
@end

@implementation UIColor (UITableViewBackground)

+ (UIColor *)groupTableViewBackgroundColor
{
    __strong static UIImage* tableViewBackgroundImage = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(7.f, 1.f), NO, 0.0);
        CGContextRef c = UIGraphicsGetCurrentContext();
        [[self colorWithRed:185/255.f green:192/255.f blue:202/255.f alpha:1.f] setFill];
        CGContextFillRect(c, CGRectMake(0, 0, 4, 1));
        [[self colorWithRed:185/255.f green:193/255.f blue:200/255.f alpha:1.f] setFill];
        CGContextFillRect(c, CGRectMake(4, 0, 1, 1));
        [[self colorWithRed:192/255.f green:200/255.f blue:207/255.f alpha:1.f] setFill];
        CGContextFillRect(c, CGRectMake(5, 0, 2, 1));
        tableViewBackgroundImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    });
    return [self colorWithPatternImage:tableViewBackgroundImage];
}

@end
Run Code Online (Sandbox Code Playgroud)

此解决方案还允许调整背景的外观.随意更改绘图代码:)


Ant*_*vre 13

在iOS6 SKD中,UIInterface.h中的注释提示如下:

组样式表视图背景不能再用简单的颜色表示.如果您希望在自己的视图中具有类似于表视图背景的背景,则应创建一个空表视图并将其放在内容后面.

在6.0种子程序期间将弃用此方法

一个简单的解决方案是使用等效的RGB值设置背景:

[self.view setBackgroundColor:[UIColor colorWithRed:215.0/255.0 green:217.0/255.0 blue:223.0/255.0 alpha:1.0]];
Run Code Online (Sandbox Code Playgroud)

您可以将视图背景设置为白色或xib中的任何颜色以禁止显示警告.


Jam*_*her 6

如果它可以帮助任何人,这里特别是我在自定义视图中所做的事情来获得这个背景(使用Beloeuvre先生的提示)

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:tv];
    [self.view sendSubviewToBack:tv];
    // ...
}
Run Code Online (Sandbox Code Playgroud)