2014-09-05 46 views
0

我有一个tableviewcontroller,其中有几个标签,textfield等单元格。我想只改变标签和文本字段的颜色。iOS更改颜色一些项目

我试着使用:

[[UILabel appearance] setTextColor:[[UtilisateurManager getCurrUser] getColor]]; 

它的工作,但问题是它改变了我的抽屉式导航栏中的标签的颜色,我不希望这样,我只是想改变项目的颜色我的tableviewcontroller。

所以,我想的是:

for(UIView *v in [self.tableView subviews]) { 
     if ([v isKindOfClass:[UILabel class]]) { 
      [(UILabel *)v setTextColor:[[UtilisateurManager getCurrUser] getColor]]; 
     } 
     else if ([v isKindOfClass:[UITextView class]]) { 
      [(UITextView *)v setTextColor:[[UtilisateurManager getCurrUser] getColor]]; 
     } etc... 
} 

但它不工作...我不明白我怎么可以更新我的tableviewcontroller的物品的颜色,没有在我的抽屉式导航栏中触摸。

THX,

回答

1

尝试 - (UITableViewCell中*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewCell *cell = ...; 

for (UIView *view in [cell.contentView subviews]) 
{ 
    NSLog(@"%@", view); 
} 

那么你应该有你的子视图,如果我unterstood你的权利。

+0

mhh,在行动中,这不是愚蠢的做到这一点。 Thx,我会尝试几个munutes。 – deveLost 2014-09-05 08:10:41

+0

确定它的工作原理,但是,我不明白为什么我的占位符也会改变颜色? – deveLost 2014-09-05 08:17:14

+0

哦不,错误,我的坏:我忘了取消我的其他测试。 – deveLost 2014-09-05 08:22:14

0

错误是下面将所有标签的颜色变化(这就像在母公司层面,从而创建的所有孩子也将改变乌尔找零)...

[[UILabel appearance] setTextColor:[[UtilisateurManager getCurrUser] getColor]]; 

所以要达到什么ü想ü可以简单地做如下,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    cell.textLabel.textColor = [UIColor blackColor]; 
    //Or 
    label.textColor = [UIColor redColor]; //Your label and textfield color you could set as per ur need. 

    return cell; 
}