IOS 取消TableView点击Cell时的色背景

为了在TableView中使用自定义的UI,所以要取消掉Cell被点击时的蓝色背景。关键代码如下:

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    CGRect recTableView = CGRectMake(3,102,316,324); 

    

    self.tableView = [[UITableView alloc]initWithFrame:recTableView style:UITableViewStylePlain];

    

    // 设置协议,意思就是UITableView类的方法交给了tabView这个对象,让完去完成表格的一些设置操作

    self.tableView.delegate = self;

    self.tableView.dataSource = self;

    

    //设置TABLE VIEW背景色

    self.tableView.backgroundColor  UIColor.clearColor;

    

    //tabView添加到视图之上

    [self.view addSubview:self.tableView];

    //    存放显示在单元格上的数据

    NSArray *arrayCarList = [NSArrayarrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", nil];

    self.aData = arrayCarList;

    

    [self.tableView setSectionIndexColor:[UIColor clearColor]];

    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];    

    [self.tableView setSeparatorColor:[UIColor clearColor]];    

    [self.tableView setBackgroundView:nil];    

    //[self.tableView setAllowsSelection:NO]; //如果TALBLEVIEW为只读的话也可以直接这样写就行了    

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    声明静态字符串型对象,用来标记重用单元格
    static NSString *TableSampleIdentifier = @"BaseCell";
    
    
    //    用TableSampleIdentifier表示需要重用的单元
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];    

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
   
    cell.contentView.backgroundColor = UIColor.clearColor;
    
    cell.backgroundColor = UIColor.clearColor;
    
    [cell.textLabel setHighlighted:NO];

……

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

........
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值