1. 程式人生 > >iOS Tableable cell 自定義點選背景效果

iOS Tableable cell 自定義點選背景效果

//先設定背景色

_backImgView = [[UIImageViewalloc]initWithFrame:CGRectMake(20 * KSCALE_X, 0, IPHONE_WIDTH - 40 * KSCALE_X, self.frame.size.height)];

_backImgView.backgroundColor = kColor(231, 231, 231);

_backImgView = [[UIImageViewalloc]initWithImage:[CommonToolscreateImageWithColor:kColor(231, 231, 231)]

highlightedImage:[CommonToolscreateImageWithColor:kColor(196, 202, 216)]];

    [self.contentViewaddSubview:_backImgView];

//設定高度

_backImgView.frame = CGRectMake(20 * KSCALE_X, 0, IPHONE_WIDTH - 40 * KSCALE_X, _speciaView.frame.size.height + _speciaView.frame.origin.y + 10);

-(UITableViewCell *)tableView:(

UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UIView *view_bg = [[UIViewalloc]initWithFrame:cell.frame];

        view_bg.backgroundColor = [UIColorclearColor];

        cell.selectedBackgroundView = view_bg;

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(

NSIndexPath *)indexPath{

DSLog(@"點選社群詳情  cell");

//當離開某行時,讓某行的選中狀態消失

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

}