is groupTableViewBackgroundColor deprecated on iOS 6?

9 Solutions Collect From Internet About “is groupTableViewBackgroundColor deprecated on iOS 6?”

This method will be deprecated during the 6.0 seed program
If you want to have a background in your own view that looks like the table view background,
then you should create an empty table view and place it behind your content.

First, add this to your viewDidLoad:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBackground.png"]];

OR

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBackground.png"]];

Then add this images to your app:

tableViewBackground.png

tableViewBackground.png

tableViewBackground@2x.png

tableViewBackground@2x.png

I’ve written a UIColor category to replace 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

This solution also allows to tweak the appearance of the background. Feel free to change the drawing code 🙂

In iOS6 SKD, comments in UIInterface.h suggest the following:

Group style table view backgrounds can no longer be represented by
a simple color.
If you want to have a background in your own view
that looks like the table view background, then you should create
an empty table view and place it behind your content.

This method will be deprecated during the 6.0 seed program

A simple solution is to set the background with equivalent RGB values:

[self.view setBackgroundColor:[UIColor colorWithRed:215.0/255.0 green:217.0/255.0 blue:223.0/255.0 alpha:1.0]];

You can them set the view background to color to White or whatever you like in the xib to suppress the warning.

If it helps anyone, here’s specifically what I’m doing in my custom view to get this background (using hint from Mr 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];
    // ...
}

Try this:

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];

You may have difficult time to locate the view if you use storyboard and have many views. You can click on “Show the Version editor” button the right top corner. This will change story view to XML text view. Search for “groupTableViewBackGroundColor”. You should find views with this attribute.

enter image description here

It’s good idea to use standard methods for previous iOs versions. So I improved solution of James Boutcher:

+ (void)setBackgroundColorForTableView:(UITableView*) tableView
{
    UIColor* color = [UIColor whiteColor];
    NSString* version = [[UIDevice currentDevice] systemVersion];
    if([version floatValue] < 6.0)
    {
        tableView.backgroundColor = color;
    }
    else
    {
        tableView.backgroundView = nil;
        UIView* bv = [[UIView alloc] init];
        bv.backgroundColor = color;
        tableView.backgroundView = bv;
        [bv release];
    }
}

Elaborating on @NSElvis’s solution, here is the identical grouped table view background asset (it’s wide enough so you don’t get funny effects in landscape orientation)

back-tableview@2x.png

To use it, simply do

[YOUR_VIEW setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"back-tableview"]]];