重载表后,UILabel的背景颜色变得清晰

时间:2017-03-30 06:45:48

标签: ios css objective-c uitableview uilabel

我在UiTableViewController工作,我用XIB创建了Custom cell。我只是将黑色设置为一个标签。听到我附上三张图片以便更好地解释。

first image for initial look of background color (B.G) of UILabel

didSelectRowAtIndexPath方法中选择时,我将其更改为蓝色。

enter image description here

主要问题是当我只是滚动我的表格时,那个标签的背景颜色变得清晰。

enter image description here

在cellForRowAtIndexpath方法中,我只是添加了这个条件,

if (inboxSelcted == 1) { 
  cell.lblNoOfIndexItem.backgroundColor = [UIColor blueColor]; 
} else { 
  cell.lblNoOfIndexItem.backgroundColor = [UIColor blackColor]; 
} 

1 个答案:

答案 0 :(得分:3)

cellForRowAtIndexpath 方法中,根据您的屏幕截图收件箱索引是这样尝试2.所以,

if (indexPath.row == 2) { 
 cell.lblNoOfIndexItem.backgroundColor = [UIColor blueColor]; 
} else { 
 cell.lblNoOfIndexItem.backgroundColor = [UIColor blackColor]; 
} 

didSelectRowAtIndexPath 方法中,

if (indexPath.row == 2) { 
 inboxSelcted = indexPath.row; 
}

尝试这样,让我知道,它是否有效!