UITableView backgroundColor always gray on iPad

前端 未结 9 1415
小蘑菇
小蘑菇 2020-11-30 18:02

When I set the backgroundColor for my UITableView it works fine on iPhone (device and simulator) but NOT on the iPad simulator. Instead I get a lig

相关标签:
9条回答
  • 2020-11-30 18:54

    tried setting backgroundColor and View for the table, had no luck (Xcode 5 iOS7.1 iPad simulator), looked OK for iPhone, but light grey background color on iPad...

    working with backgroundColor for the cell itself fixed this for me on iOS 7.1 4/2014

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
            static NSString *CellIdentifier = @"ViewSomeTriggerCell";
    
            // get a cell or a recycled cell
            sictVCViewSomeTriggerCell *cellTrigger = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
            // put a picture and a word in the cell (positions set in .xib)
            NSString * tname = [self.fetchedTriggersArray objectAtIndex:indexPath.row];
            cellTrigger.imageTrigger.image = [UIImage imageNamed:@"icon_appicon.png"];
            cellTrigger.labelName.text = tname;
    
            // set background color, defeats iPad wierdness
            // http://stackoverflow.com/questions/2688007/uitableview-backgroundcolor-always-gray-on-ipad
    
            // clearColor is what I wanted, and it worked, also tested with purpleColor
            cellTrigger.backgroundColor =[UIColor clearColor];
            return cellTrigger;
    

    }

    0 讨论(0)
  • 2020-11-30 18:58

    I think it is worth noting that as of Xcode 6.1 and iOS 8.1, specifically for iPad (if you want to set cell background as well) it seems that you must set table background AND cell background.

    For instance, on an iPhone storyboard you can set a cell to clear color, then set background image of table programmatically for a transparent table with background image. However if you were to view this same configuration on iPad the cells would not be clear. Cells will need to be set to clear programmatically for iPad.

    0 讨论(0)
  • 2020-11-30 19:00
    • Simulating iPad 2
    • Running iOS 7.1 through 8.3
    • Built from XCode 6.3

    None of the above worked for my UIViewController->UITableView specified using a single XIB. What did work was moving the whole setup into a Storyboard, and setting the background color using the IB inspector.

    0 讨论(0)
提交回复
热议问题