2009-10-01 32 views
10
Ben yarı saydam bir renge UITableViewCells backgroundColor set

, iyi görünüyor, ama renk tüm hücre kapsamaz.UITableViewCell saydam arka plan

imageView ve accessoryView çevresi hücre en backgroundColor aynı renkte olmasını açıkça cell.accessoryView.backgroundColor ve cell.imageView.backgroundColor ayarlama denedim

alt text

... [UIColor clearColor] olarak geliyor, ancak edilir çalışmıyor Simgenin etrafında küçük bir kutu koyar, ancak sol kenarı doldurmak için genişlemez. Sağ kenar bundan etkilenmez gibi görünüyor.

Bunu nasıl düzeltebilirim?

DÜZENLEME:

- (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; 
} 

cevap

16

Ben ve ben burada bu kimseye yakalar durumunda grup için özet, bugün bu anladım.

Sen hücre arka plan ve cell.textLabel.backgroundColor her zaman cellForRowAtIndexPath denir, sadece alloc/init aşamasında (yani tableView dequeue önbellek bayan varsa) belirlemek zorunda.

Yani, kod bu olur: ilham almak için bu makaleye kullanıyordum, ama ne yazık ki geçirgen piller kullanmaz

- (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

aslında 1 şey daha yapmak zorunda kaldı. Cell.textLabel.backgroundColor ayarlanması gerekiyor * Hücrenin arka plan rengi * AFTER *. Bunu neden yapmaya ihtiyacım olduğuna dair bir fikrim yok, ama şimdi çalışıyor. Teşekkürler Mike! –

2

hücre en contentView arka plan rengini ayarlama ve hücre, aksesuar tutarak ve görüntü görünümleri şeffaf baktınız mı: İşte çiğ tablo hücre kodudur? Ayrıca

, this article bazı alternatifler gösterilmesine yardımcı olabilir.

+0

. İçeriğin ayarlanmasıGörünüm renginin çok garip etkileri vardı. Ayrıca contentView.opaque = NO ayarlamayı denedim, ancak yine de berbat görünüyordu. –

İlgili konular