2010-01-07 67 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]; 
} 
相關問題