2014-09-05 114 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; 
}