天天看點

UITableViewCell 的簡單背景以及 選中背景設定

             1,設定Cell 背景 Color:

 cell.backgroundColor=[UIColor clearColor];    

             2,設定Cell 背景 View: 

         cell.backgroundView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];

     3,設定Cell 選中背景 View: 

 cell.selectedBackgroundView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];

     4,為不同cell設定不同的 背景,可以通過自定義方法:

  -(void)willBeSetedCell:(UITableViewCell*)cell AndIndexPath:(NSIndexPath*)index{

       UIImageView *backgroundView=[[UIImageView alloc] initWithFrame:CGRectZero];

       UIImageView *selectedView=[[UIImageView alloc] initWithFrame:CGRectZero];

        if([_data count] - 1 == index.section) {

        backgroundView.image=[UIImage imageNamed:@"tableCell_single"];

        selectedView.image=[UIImage imageNamed:@"tableCell_single_tapped"];

        }

    cell.backgroundView=backgroundView;

    cell.selectedBackgroundView=selectedView;

}