2014-05-20 39 views
0

我是iOS新手,很抱歉我的英語不好。 我想通過 UIAppearance代理將外觀主題更改爲我的應用程序。然後我有一些不同的單元格,它們是UITableViewCell的子類,每個單元格都有一個樣式。 某些單元格中的某些標籤具有不同的顏色,因此單元格的「textLabel」屬性在單元格中可能具有白色,而在另一個單元格中可能具有紅色。從UITableViewCell的子類返回自定義的UILabel(編程)

我有一個UILabel子類,例如,文本的紅色。 我改變外觀顏色爲這個標籤如下:

[[MyRedLabel appearance] setTextColor:[UIColor redColor]]; 

我想使用相同的小區所以我所做的就是覆蓋這樣的方法:

-(UILabel*) textLabel { 
    //(MyRedLabel is only put for test purposes, lastly I'll remove it by a property that  will be what I want) 
    return [[MyRedLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
} 

的問題是,當的TableView繪製細胞,文字不是。請你能幫助我嗎? 謝謝。

[編輯]

對不起,如果我不解釋。我有一個UILabel對,我想每一種顏色的子類,所以如果我想藍色的標籤我這樣做:

[[MyBlueLabel appearance] setTextLabel:[UIColor blueColor]]; 

我想要的是分配,我想一個單元標籤:

//Cell1 
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"]; 

if (cell == nil) { 
    cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

cell.textLabel = [[MyBlueLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
//... 
//Cell2 

//.... 
cell.textLabel = [[MyRedLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 

然後當我做cell.textLabel.text = @「嗨世界」;文本將在cell1中爲藍色,在cell2中爲紅色。

我想知道這是否是正確的,因爲我不希望創建4個或更多定製單元與他的.xib

回答

0

並不清楚你的要求。但是你不應該使用[MyReadLabel外觀]來設置屬性,除非你想讓你所有的UILabel以同樣的方式運行。就像你所說的那樣,我認爲你濫用了這些方法。

相關問題