修改Cell的点击效果(背景 颜色)

来源:互联网 发布:mac更换系统字体 编辑:程序博客网 时间:2024/05/01 19:57
//修改cell点击的背景图片 cell.selectedBackgroundView = [[[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"图片"]stretchableImageWithLeftCapWidth:25 topCapHeight:25]] autorelease];//修改Cell的背景颜色@property (nonatomic, retain) UIView *selectedBackgroundView;//在方法中执行-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{   NSString * strID = @"ID";    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strID];   if (cell == nil) {    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID] autorelease];   }//修改Cell的分割线   tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;    [tableView setSeparatorColor:[UIColor redColor]];   cell.contentView.backgroundColor = [UIColor clearColor];//先清除背景颜色   UIView *view = [[UIView alloc] initWithFrame:cell.contentView.frame];   view.backgroundColor = [UIColor redColor];设置选中后cell的背景颜色   self.selectedBackgroundView =view;       return cell;  }


原创粉丝点击