Tuesday, 30 September 2014

Change UITableView Cell Selection Color

You can change the highlight Color in several ways.
  1. Change the selectionStyle property of your cell to UITableViewCellSelectionStyleGray. If you change it to , it will be gray.
  2. Change the selectedBackgroundView property. Actually what creates the blue gradient is a view. You can create a view and draw what ever Color you like, and use the view as the background of your table view cells.
  3. You can also set None UITableViewCellSelectionStyleNone to it. that means there will be no Selection Style.

Write below code into -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

This is to make it gray.

if(cell == nil)
{
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
}



This code is for setting your choice color

if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor = [UIColor clearColor];
        
        UIView *bgColorView = [[UIView alloc] init];
        bgColorView.backgroundColor = [UIColor greenColor];
        [cell setSelectedBackgroundView:bgColorView];


    }




You can also set RGB color to it just like below code.

if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor = [UIColor clearColor];
        
        UIView *bgColorView = [[UIView alloc] init];
        bgColorView.backgroundColor = [UIColor colorWithRed:255.0/256.0 green:139.0/256.0 blue:15.0/256.0 alpha:1];
        [cell setSelectedBackgroundView:bgColorView];
    }


                                                                                                                                                                     
Thanks & Regards
 Angel AppTech











No comments:

Post a Comment

Note: only a member of this blog may post a comment.