2009-10-01 8 views
10

Wenn ich die UITableViewCells backgroundColor auf eine halbtransparente Farbe einstelle, sieht es gut aus, aber die Farbe bedeckt nicht die gesamte Zelle.UITableViewCell transparenter Hintergrund (einschließlich imageView/accessoryView)

Die Gegend um das imageView und accessoryView kommen auf, als [UIColor clearColor] ...

alt text

ich die cell.accessoryView.backgroundColor und cell.imageView.backgroundColor Einstellung versucht haben ausdrücklich die gleiche Farbe wie die Zelle backgroundColor, aber es ist funktioniert nicht. Es wird ein kleines Kästchen um das Symbol gelegt, aber es wird nicht erweitert, um die linke Kante zu füllen. Der rechte Rand scheint davon nicht betroffen zu sein.

Wie kann ich das beheben?

EDIT: Hier ist der rohe Tabellenzelle Code:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.opaque = NO; 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4]; 
     cell.textColor = [UIColor whiteColor]; 
    } 

    cell.imageView.image = [icons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [items objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 

Antwort

16

Ben und ich haben das heute herausgefunden, hier ist die Zusammenfassung für die Gruppe, falls das irgendjemand anderes betrifft.

Sie haben die Zelle Hintergrund einstellen und cell.textLabel.backgroundColor jedes Mal cellForRowAtIndexPath genannt wird, nicht nur während der alloc/init Phase (das heißt, wenn die tableView hat eine dequeue Cache-Miss).

So wird der Code folgendermaßen aus:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     cell.opaque = NO;   
    } 

    // All bgColor configuration moves here 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4]; 
    cell.textColor = [UIColor whiteColor]; 
    cell.imageView.image = [icons objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [items objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 
+1

eigentlich musste ich noch 1 Sache machen. Die cell.textLabel.backgroundColor musste * NACH * der Hintergrundfarbe der Zelle gesetzt werden. Ich habe keine Ahnung, warum ich das tun muss, aber jetzt funktioniert es. Danke Mike! –

2

Haben Sie in sahen die Hintergrundfarbe der Zelle contentView Einstellung und hält die Zelle, Zubehör und Bildansichten transparent?

Auch könnte this article Ihnen helfen, einige Alternativen zu zeigen.

+0

ich diesen Artikel für Inspiration wurde mit, aber leider ist er nicht transparent Zellen verwenden. Die Einstellung der Hintergrundfarbe contentView hatte sehr seltsame Auswirkungen. Ich habe auch versucht, contentView.opaque = NO, aber immer noch sah schrecklich aus. –

Verwandte Themen