Search This Blog

Monday, 20 August 2012

How to change cell Background and SelectionView in TableView for xcode

Hello Friends,
                      Here is a code to use any image for tableView's cell Background and selection View,Follow the code:

CODE:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell==nil){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    UIView *selectionView = [[UIView alloc]initWithFrame:cell.bounds];
    [selectionView setBackgroundColor:[UIColor colorWithRed:0.875 green:0.004 blue:0.004 alpha:1] ];
    UIImageView *CellBack = [[UIImageView alloc]initWithFrame:cell.bounds];
    [CellBack setImage:[UIImage imageNamed:@"transparent.png"]];//transparent.png is a image that i wana use as a cell background

    cell.backgroundView = CellBack;
    cell.backgroundColor = [UIColor clearColor];
        cell.textColor = [UIColor whiteColor];
        
    cell.selectedBackgroundView = selectionView;
    cell.selectedTextColor = [UIColor whiteColor];

    cell.textLabel.text=[station objectAtIndex:indexPath.row];
    if([genre objectAtIndex:indexPath.row]!=NULL){
    cell.detailTextLabel.text =[NSString stringWithFormat:@"Genre: %@", [genre objectAtIndex:indexPath.row]];
        arrow = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
      
    }







No comments:

Post a Comment