2010-07-20 14 views
7

मेरे पास एक UITableView है और सभी कोशिकाओं में पृष्ठभूमि छवि लागू करना चाहूंगा। प्रत्येक सेल के लिए मेरी ऊंचाई चर है। पृष्ठभूमि छवि बनाने के बारे में मुझे कैसे जाना चाहिए?विभिन्न ऊंचाइयों के साथ UITableViewCell पृष्ठभूमि छवि कैसे सेट करें?

cell.contentView.backgroundColor = [UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
+0

यह मेरे लिए काम नहीं करता है (टाइपो ठीक करने के बाद) दे सकते हैं के लिए इसी तरह कुछ कर सकते हैं। –

उत्तर

3

एक विचार यह है कि UIImage पर एक खिंचाव वाली छवि के साथ रखना है। इस तरह, इससे कोई फर्क नहीं पड़ता कि पंक्ति की ऊंचाई क्या है, छवि मिलान करने के लिए फैल सकती है।

तुम भी मैट here with a gradient layer

+0

क्या आप खिंचाव वाली छवि का वर्णन कर सकते हैं? क्या मुझे कुछ 1x55 पिक्सेल (केवल एक उदाहरण) छवि बनाने की आवश्यकता होगी और जो स्वचालित रूप से एक्स-प्लेन पर फैलाएगा या अतिरिक्त कोड आवश्यक है? –

+3

आप मूल रूप से केवल एक छवि देते हैं और फिर बताते हैं कि कौन से हिस्सों को '[[UIImage imageNamed: @ "someBGImage.png"] stretchableImageWithLeftCapWidth: 5 topCapHeight: 5] के माध्यम से फैला नहीं जा सकता है;' जहां 5 पिक्सल वह हिस्सा है जो ' टी खिंचाव (एक सीमा की तरह)। अधिक जानकारी http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight: – iwasrobbed

2

क्या किया है cellForRowAtIndexPath विधि में आप सेल पृष्ठभूमि रंग

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


{ 
    static NSString *cellIdentifier = @"Cell"; 
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) 
    {  
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 
// for cell background color 
    cell.backgroundView =[[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"tab2.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 

// for selection color  
    cell.selectedBackgroundView =[[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"selected.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 
    return cell; 
} 
संबंधित मुद्दे