2010-10-20 31 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

相关问题