2013-02-20 13 views
6

में टॉबाउंड्स मैं अपने UITextView के कोनों को समूहित UITableViewCell के गोलाकार कोनों से मुखौटा करने की कोशिश कर रहा हूं जिसमें यह शामिल है। यहाँ सेल का एक स्क्रीनशॉट के रूप में यह वर्तमान मेंक्लिप टॉबाउंड्स और मास्क समूहबद्ध यूआईटीबल व्यूसेल

UITextView inside grouped UITableViewCell

खड़ा है यहाँ कोड मैं अपने कोशिकाओं सीमाओं ओवरलैपिंग से कोनों को रोकने के लिए प्रयास करने के लिए उपयोग कर रहा हूँ में से कुछ है। मैंने कोशिश की दोनों

cell.contentView.layer.masksToBounds = YES; 
cell.layer.masksToBounds = YES; //tried this as a test, still doesn't work 
detailTextView.clipsToBounds = YES; 
[cell.contentView addSubview:detailTextView]; 

और

cell.layer.masksToBounds = YES; 
cell.contentView.layer.masksToBounds = YES; 
detailTextView.clipsToBounds = YES; 
[cell addSubview:detailTextView]; 

यह स्पष्ट रूप से काम नहीं कर रहा है, क्या मुझे याद आ रही है?

+0

क्या आपने 'cell.clipsToBounds = YES;' कोशिश की है? – Patrick

+0

हां, लेकिन वही नहीं है जो मुझे वैसे भी चाहिए। 'क्लिप टूबाउंड्स' का अर्थ है कि सेल इसके परतों के हिस्सों को छिपाएगा जो उसके माता-पिता के बाहर हैं। मैं 'UITextView' को अपने माता-पिता के बाहर अपनी परत के हिस्सों को छिपाने के लिए चाहता हूं (कोशिकाओं की सामग्री दृश्य/सेल स्वयं) – conorgriffin

+1

आपकी सामग्री की सीमाएं आपके सेल की सीमाओं से बड़ी हैं, इसलिए सामग्रीदृश्य को क्लिप करना आपकी समस्या का समाधान नहीं करेगा - आप सेल – Pfitz

उत्तर

0

मुझे पूरा यकीन है कि आप इस तरह कोनों को मुखौटा नहीं कर सकते हैं। सेल की backgroundView समूहबद्ध UITableView के लिए एक छवि है इसलिए मास्किंग की कोई समझ नहीं है।

समस्या का एक संभावित समाधान स्वयं कोनों के चारों ओर घूमना होगा। यह थोड़ा मुश्किल है क्योंकि आप केवल शीर्ष सेल के शीर्ष कोनों और नीचे के सेल के निचले कोनों को गोल करना चाहते हैं। सौभाग्य से, @lomanf ने यहां मनमाने ढंग से कोनों को घेरने के लिए एक अच्छा समाधान पोस्ट किया: Round two corners in UIView। अपने MTDContextCreateRoundedMask विधि का उपयोग करके, हम अपने लक्ष्य को प्राप्त कर सकते हैं।

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Other cell instantiation 

    // First cell in section 
    if (indexPath.row == 0) { 
     [self roundTopOrBottomCornersOfCell:cell top:YES];  
    } 
    // Last cell in section 
    else if (indexPath.row == tableView.numberOfRowsInSection:indexPath.section-1) { 
     [self roundTopOrBottomCornersOfCell:cell top:NO]; 
    } 
} 

// Modified from the second part of @lomanf's Solution 1 
- (void)roundTopOrBottomCornersOfCell:(UITableViewCell*)cell top:(BOOL)top { 
     // Set constant radius 
     CGFloat radius = 5.0; 

     // Create the mask image you need calling @lomanf's function 
     UIImage* mask; 
     if (top) { 
      mask = MTDContextCreateRoundedMask(self.view.bounds, radius, radius, 0.0, 0.0); 
     } 
     else { 
      mask = MTDContextCreateRoundedMask(self.view.bounds, 0.0, 0.0, radius, radius); 
     } 

     // Create a new layer that will work as a mask 
     CALayer* layerMask = [CALayer layer];    
     layerMask.frame = cell.bounds; 

     // Put the mask image as content of the layer 
     layerMask.contents = (id)mask.CGImage; 

     // Set the mask layer as mask of the view layer 
     cell.layer.mask = layerMask; 
}   
0

एक ही समस्या मुझे

लिए हुआ अंतर यह है कि मैं सादे शैली का उपयोग कर रहा है और मैं गोल कोने के साथ हर कोशिका बनाने के लिए कोशिश कर रहा हूँ है। अंत में, मैं इसे बनाया है, यहाँ मेरा तरीका है:

1. डाल अपने कस्टम में इस कोड tableViewCell के awakeFromNib विधि

[cell.layer setMasksToBounds:YES]; 
    [cell.layer setCornerRadius:5.0]; 

2. सफेद रंग के लिए अपने कस्टम TableViewCell के contentView की पृष्ठभूमि का रंग निर्धारित करते हैं, तो सेट रंग को साफ़ करने के लिए आपकी तालिका दृश्य का बैकग्राउंग रंग। बस इतना ही।

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