is groupTableViewBackgroundColor deprecated on iOS 6?

后端 未结 9 1377
-上瘾入骨i
-上瘾入骨i 2020-11-28 09:56

I was just testing my app with iOS 6.0 and Xcode 4.5GM and I have set up a view like this:

[self.view setBackgroundColor:[UIColor groupTableViewBackgroundCol         


        
相关标签:
9条回答
  • 2020-11-28 10:27

    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 :)

    0 讨论(0)
  • 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];
        // ...
    }
    
    0 讨论(0)
  • 2020-11-28 10:35

    Try this:

    [myTableView setBackgroundView:nil];
    [myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];
    
    0 讨论(0)
提交回复
热议问题