2010-10-20 85 views

回答

2

要得到任何你想要的顏色,你必須用自己的UIView更換selectedBackgroundView。

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"CellID"; 
    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     UIView *selectedBackground = [[[UIView alloc] init] autorelease]; 
     selectedBackground.backgroundColor = [UIColor magentaColor]; 
     cell.selectedBackgroundView = selectedBackground; 
    } 
    // configure cell 
    return cell; 
} 
+0

+1感謝...我嘗試過,併成功,但框架不是roundRect .... – Saawan 2010-10-21 04:49:27

+0

是的,這不會在分組風格。用分組風格實現同樣的事情要困難得多。一種方法是繼承UIView,就像在http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/ – 2010-10-21 09:33:24

1

您可以設置的tableView單元屬性

cell.selectionStyle = UITableViewCellSelectionStyleGray; 
+0

只有藍色和灰色的顏色..... – Saawan 2010-10-20 13:04:42

+0

+1 Gyani一起姬回覆Kijiye – Saawan 2010-10-21 05:01:20

+0

是通過將獲得藍色和灰色的顏色 – Gyani 2010-10-21 05:12:59

1

製作你自己的UITableViewCell的子類。覆蓋的方法-(void)setSelected:(BOOL)selected

事情是這樣的:?

- (void)setSelected:(BOOL)selected { 
     [super setSelected:selected]; 
     if (selected) { 
      self.backgroundColor = [UIColor greenColor]; 
     } else { 
      self.backgroundColor = [UIColor whiteColor]; 
     } 
} 
+0

+1中所做的那樣:好的但是問題是如何使用它與我的類已經tableview和哪些是UIViewController的子類...實際上是從未使用的UITableViewCell的子類...所以請給出相應的想法.... – Saawan 2010-10-21 05:00:21

相關問題