Change background of a grouped UITableView

后端 未结 8 652
情歌与酒
情歌与酒 2020-12-31 01:16

I\'m having some trouble trying to change the background of a UITableView with groups.

_tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage i         


        
相关标签:
8条回答
  • 2020-12-31 01:28

    You additionally need to disable the background view of _tableView:

    [_tableView setBackgroundView:nil];
     _tableView.backgroundColor = [UIColor redColor];
    

    No need to add new view to backgroundView. This is working for me in iOS6.

    0 讨论(0)
  • 2020-12-31 01:28

    why don't you set the tableView.backgroundView? you can alloc an image view withe the specified image and pass it to the background view instead of setting the background color.

    0 讨论(0)
  • 2020-12-31 01:32

    Just want to add to Nirav's answer - it can also be done using the iOS 5 appearance proxy.

    [[UITableView appearance] setBackgroundView:nil];
    [[UITableView appearance] setBackgroundColor:[UIColor lightGreyColor]];
    

    The advantage is that it is applies globally, so you can group all your UI customisations in one place. However, it will apply to all tableViews (not just grouped style).

    0 讨论(0)
  • 2020-12-31 01:38
    tableView.backgroundView = nil;
    tableView.backgroundColor = [UIColor colorWithPatternImage: xxx];
    // tableView.backgroundColor = [UIColor redColor];  // is ok
    

    if you set set the backgroundColor as this, when you scroll the tableView, the backgroundColor view will scroll also. so, you can: tableView.backgroundView = nil; self.view.backgroundColor = ...

    0 讨论(0)
  • 2020-12-31 01:46

    Swift 4.2

    TO REMOVE BACKGROUND VIEW & COLOR

    tableView.backgroundView = nil
    tableView.backgroundColor = .clear
    
    0 讨论(0)
  • 2020-12-31 01:49

    For iOS 9+, changing the background color of the UITableView is enough.

    Objective-C

    tableView.backgroundColor = [UIColor redColor];
    

    Swift

    tableView.backgroundColor = .red
    
    0 讨论(0)
提交回复
热议问题