2009-10-01 15 views
10

जब मैं UITableViewCells backgroundColor को सेमी-पारदर्शी रंग में सेट करता हूं, तो यह अच्छा लगता है, लेकिन रंग पूरे सेल को कवर नहीं करता है।UITableViewCell पारदर्शी पृष्ठभूमि (imageView/accessoryView सहित)

imageView और accessoryView के आसपास के क्षेत्र सेल की backgroundColor के रूप में एक ही रंग होने के लिए

alt text

मैं स्पष्ट रूप से cell.accessoryView.backgroundColor और cell.imageView.backgroundColor स्थापित करने की कोशिश की है [UIColor clearColor] के रूप में आ रहे हैं ..., लेकिन यह काम नहीं करता यह आइकन के चारों ओर एक छोटा सा बॉक्स रखता है, लेकिन बाएं किनारे को भरने के लिए विस्तार नहीं करता है। दायां किनारा इस से अप्रभावित लगता है।

मैं इसे कैसे ठीक कर सकता हूं?

संपादित:

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

उत्तर

16

बेन और मैंने आज इसे समझ लिया, यहां समूह के लिए सारांश है यदि यह किसी और को पकड़ लेता है।

आप सेल पृष्ठभूमि और cell.textLabel.backgroundColor हर बार cellForRowAtIndexPath कहा जाता है, न सिर्फ alloc/init चरण के दौरान (अर्थात tableView एक विपंक्ति कैश याद आती है) सेट करना होगा।

तो, कोड इस हो जाता है:

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

वास्तव में मुझे 1 और चीज करना पड़ा। Cell.textLabel.background रंग को * सेल के पृष्ठभूमि रंग के बाद * सेट करने की आवश्यकता है। मुझे नहीं पता कि मुझे ऐसा करने की ज़रूरत क्यों है, लेकिन अब यह काम कर रहा है। धन्यवाद माइक! –

2

आप सेल की contentView की पृष्ठभूमि का रंग की स्थापना और सेल, गौण रखते हुए, और छवि विचारों पारदर्शी में देखा है: यहाँ कच्चे तालिका सेल कोड है?

इसके अलावा, this article आपको कुछ विकल्प दिखाने में मदद कर सकता है।

+0

मैं प्रेरणा के लिए है कि लेख उपयोग कर रहा था, लेकिन दुर्भाग्य से वह पारदर्शी कोशिकाओं का उपयोग नहीं करता। सामग्री सेट करना दृश्य पृष्ठभूमि रंग बहुत अजीब प्रभाव पड़ा। मैंने contentView.opaque = NO को सेट करने का भी प्रयास किया, लेकिन फिर भी भयानक लग रहा था। –

संबंधित मुद्दे