![](/img/trans.png)
[英]How to Dynamically Change UIImageView color in tableviewcell in Swift?
[英]How to change tableViewCell background color
注意:這是關於GROUPED tableView中的單元格 。 與普通的tableView相比,這有很大的不同! 默認的單元格自定義答案在這種情況下不起作用,因此請先驗證您的答案。
這是我設置灰色屏幕和黃色tableView背景的方式:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
UIView *myView = [[UIView alloc] initWithFrame:magicRect];
myView.backgroundColor = [UIColor yellowColor];
[self.tableView addSubview:myView];
[self.tableView sendSubviewToBack:myView];
}
這就是我設置綠色單元格背景的方式。 從圖片中可以看到,它缺少一些區域:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"Cell"] autorelease];
cell.backgroundColor = [UIColor greenColor];
}
// Configure the cell...
}
問題:如何在tableView單元格的開頭和結尾更改顏色 ? 現在,該單元格在這些區域中是透明的,並在整個tableView下方顯示self.view.backgroundColor。 這些區域實際上是透明的,因為在滾動tableView時,帶紋理的背景保持在同一位置。
像這樣將tableView背景設置為清晰的顏色,
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setBackgroundColor:[UIColor clearColor]];//Here you can give as yellow instead of adding view
//ur code
}
我不知道為什么要向表視圖添加子視圖,可以為表視圖設置背景顏色:
tview.backgroundColor=[UIColor yellowColor];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.