iphone how to I make a uitableviewcellaccessorydis

2019-05-05 07:13发布

问题:

Can someone please explain to me how I can make a uitableviewcellaccessorydisclosureindicator's background in a UITableViewCell transparent?

Right now I'm facing this problem:

alt text http://www.bubl3r.com/disclosure.jpg

回答1:

Just found the answer. Turns out it was just 3 lines & having to define my own disclosure indicator .png image with a transparent background:

UITableViewCell *bgView = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor=indexPath.row % 2? [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1]: [UIColor whiteColor];
    bgView.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosure.png"]];
    cell.backgroundView=bgView; 


    return cell;


回答2:

In your UITableView's delegate, override the delegate method tableView:willDisplayCell:forRowAtIndexPath:. In there, set the cell's backgroundColor property to whatever color, and the accessory view's background color should match.



回答3:

More detail from anshuchimala's answer:

cell.contentView.backgroundColor=[UIColor grayColor];//or any color
cell.backgroundColor=[UIColor grayColor];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView.backgroundColor=[UIColor clearColor];