UITableView backgroundColor always gray on iPad

前端 未结 9 1447
小蘑菇
小蘑菇 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:39

    If your application targets both iPhone and iPad you can do it like this:

    [myTableView setBackgroundColor:[UIColor clearColor]]; // this is for iPhone
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
        [myTableView setBackgroundView:nil];
        [myTableView setBackgroundView:[[UIView alloc] init]];
    } // this is for iPad only
    

    Notice that the TableView alloc doesn't have autorelease for ARC.

提交回复
热议问题