我有一个uitableview单元格添加了一些像这样的标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIImage* myImage = [UIImage imageNamed:@"AccessoryForDealsMain.png"];
UIImageView *MyimageView = [[UIImageView alloc] initWithImage:myImage];
MyimageView.contentMode=UIViewContentModeScaleToFill;
cell.accessoryView=MyimageView;
[MyimageView release];
UILabel *BluePatti = [[UILabel alloc] init];
BluePatti.frame=CGRectMake(0,0,4,44);
BluePatti.backgroundColor = BLUEPATTI;//[UIColor blueColor];
UILabel *BlackLine = [[UILabel alloc] init];
BlackLine.frame=CGRectMake(3,0,1, 45);
BlackLine.backgroundColor = BLACK_LINE;
[BluePatti addSubview:BlackLine];
[BlackLine release];
[cell.contentView addSubview:BluePatti];
[BluePatti release];
UILabel *Seperator = [[UILabel alloc] initWithFrame:CGRectZero];
Seperator.backgroundColor = [UIColor colorWithRed:234/256.0 green:234/256.0 blue:234/256.0 alpha:1.0]; //[UIColor lightGrayColor];
Seperator.frame = CGRectMake(4,43,316,1);
[cell.contentView addSubview:Seperator];
[Seperator release];
}
if(indexPath.section==5)
{
cell.textLabel.text=[self.GenderCellData objectAtIndex:indexPath.row];
cell.textLabel.textColor=CELL_TEXT_COLOR;
cell.textLabel.font=CELL_FONT;
}
else
{
cell.textLabel.text=@"Cells";
cell.textLabel.font=CELL_FONT;
}
return cell;
}
现在,当我触摸单元格时,它会在所有子视图上方显示蓝色选择。如何更改选择框架和颜色?
答案 0 :(得分:0)
您可以在UITableViewCell
中创建具有自己的框架和颜色的自定义selectedBackgroundView。当选择单元格而不是默认的蓝色背景时,将显示此信息。
例如:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)];
view.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = view;
[view release];
答案 1 :(得分:0)
我今天面临同样的问题,我通过这段代码解决了
首先,在我的自定义单元格初始化
<script src="//cdnjs.cloudflare.com/ajax/libs/EaselJS/0.8.0/easeljs.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/TweenMax.min.js"></script>
<canvas id="mainCanvas" width="800" height="800"></canvas>
第二集selectionStyle无
self.customerbgImageview = [UIImageView new];
[self.customerbgImageview setFrame:CGRectMake(0 , 11, Width, 66)];
[self.customerbgImageview setBackgroundColor:UIColor_RGB(0, 255, 255, 0.5)];
[self addSubview:self.customerbgImageview];
表格方法中的第三个
cell.selectionStyle = UITableViewCellSelectionStyleNone;