2010-01-07 71 views
2

我有一个UITableView的单元格现在增加了一些标签是这样的有没有办法在有限的框架上显示Uitableviewcell选择?

- (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 
{ 
    [email protected]"Cells"; 
    cell.textLabel.font=CELL_FONT; 
} 
return cell; 
} 

当我抚摸它的细胞显示了所有subviews.How更改我的选择框颜色和上面的蓝色选择?

回答

0

您可以在UITableViewCell中创建具有自己的框架和颜色的自定义selectedBackgroundView。这将显示单元格被选中,而不是默认的蓝色背景。

例如:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)]; 
view.backgroundColor = [UIColor redColor]; 
cell.selectedBackgroundView = view; 
[view release]; 
+2

但它在完整cell.i显示已经使用this.I只是想表明有限的框架上的选择,但仍然没有成功 – 2010-01-09 10:24:43

+0

是的,我会同意你不能设置你自己的框架。无论如何,这对我无效。 – 2012-03-01 15:30:31

0

我今天所面临的同样的问题,我通过这个代码

首先,在我的自定义单元格的init

 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]; 

第二套解决selectionStyle none

0123在表的方法
cell.selectionStyle = UITableViewCellSelectionStyleNone; 

第三

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    CustomOrderTableViewCell *cell = (CustomOrderTableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; 
    [cell.customerbgImageview setHidden:NO]; 

} 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    CustomOrderTableViewCell *cell = (CustomOrderTableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; 
    [cell.customerbgImageview setHidden:YES]; 
} 
相关问题