2015-06-15 13 views
6

के साथ काम नहीं कर रहा है UIUezierPath के साथ उपयोग करते समय मुझे UITableViewCell में ऑटो लेआउट बाधाओं में समस्या हो रही है। मेरा सेल पूरी चौड़ाई नहीं जायेगा। आप छवि 1 और छवि 2 के बीच अलग-अलग देख सकते हैं। छवि 2 मैंने गोल कोनों को नहीं जोड़ा।UITableViewCell ऑटो लेआउट चौड़ाई UIBezierPath

छवि 1 With UIBezierPath

छवि 2 Without UIBezierPath

इससे पहले, मैं UIView में UIBezierPath के साथ एक ही समस्या आ रही है (आप के साथ पहले 2 UIView देख सकते हैं "0") । वैकल्पिक हल मैं उपयोग कर रहा हूँ कोड नीचे की तरह viewDidLayoutSubviews में गोलाई कोनों मुखौटा करने के लिए है: -

- (void)viewDidLayoutSubviews { 
    [super viewDidLayoutSubviews]; 
    [self.view layoutIfNeeded]; 

    UIView *container = (UIView *)[self.view viewWithTag:100101]; 
    [container setBackgroundColor:[UIColor colorWithHexString:@"ffffff"]]; 
    [self setMaskTo:container byRoundingCorners:UIRectCornerAllCorners]; 
} 

लेकिन अब मैं UITableViewCell में अटक कर रहा हूँ क्योंकि मैं नहीं कर सकते viewDidLayoutSubviews में गोलाई कोनों जोड़ें। नीचे के रूप में मेरे कोड: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"myData"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    MyWClass *w = [_wData objectAtIndex:indexPath.row]; 

    UIView *container = (UIView *) [cell viewWithTag:200001]; 
    [container setBackgroundColor:[UIColor colorWithHexString:w.bgColor]]; 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:container.layer.bounds 
                byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight 
                 cornerRadii:CGSizeMake(10.0, 10.0)]; 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = container.bounds; 
    maskLayer.path = maskPath.CGPath; 
    container.layer.mask = maskLayer; 

    [cell setBackgroundColor:[UIColor colorWithHexString:@"#efeff4"]]; 
    cell.layer.masksToBounds = NO; 
    cell.layer.shadowOpacity = 1.0; 
    cell.layer.shadowOffset = CGSizeMake(0, 2); 
    cell.layer.shadowColor = [UIColor colorWithHexString:@"#e4e4e8"].CGColor; 
    cell.layer.shadowRadius = 0; 

    return cell; 
} 

मैं [cell.contentView layoutIfNeeded]; लेकिन अभी भी एक ही जोड़ने की कोशिश।

किसी भी मदद की सराहना की जाएगी।

+0

'container.layer.masksToBounds = हाँ,' या 'कोशिश की -clipsToBounds' – 0yeoj

+0

@ 0yeoj, अभी भी काम नहीं कर रहा – skycrew

+0

आप गुप्त अपनी कोशिकाओं से स्क्रॉल, वे खुद को ठीक करते हैं जब आप उन्हें वापस स्क्रॉल ? – stefandouganhyde

उत्तर

0
तर्क मेरे लिए काम कर नीचे

:

अपने UIView चौड़ाई सेल चौड़ाई के बराबर निर्धारित किया है।

पूर्व: container.frame.size.width = cell.frame.size.width

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