2015-06-15 14 views
6

Mam problem z ograniczeniami układu automatycznego w UITableViewCell podczas używania z UIBezierPath. Moja komórka nie będzie miała pełnej szerokości. Możesz zobaczyć różnice między Obrazem 1 a Obrazem 2. Obrazek 2 Nie dodałem zaokrągleń narożników.UITableViewCell Automatyczna szerokość układu Nie działa z UIBezierPath

Obrazek 1 With UIBezierPath

Obraz 2 Without UIBezierPath

Wcześniej Mam ten sam problem z UIBezierPath w UIView (widać pierwsze 2 UIView z "0") . Obejście używam jest do maskowania zaokrąglenia narożników w viewDidLayoutSubviews jak poniżej kodów: -

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

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

Ale teraz utknąłem w UITableViewCell ponieważ nie mogę dodać zaokrąglenia narożników w viewDidLayoutSubviews. Moje kody jak poniżej: -

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

Próbuję dodać [cell.contentView layoutIfNeeded];, ale wciąż tak samo.

Każda pomoc zostanie doceniona.

+0

'container.layer.masksToBounds = TAK;' lub '-clipsToBounds' – 0yeoj

+0

@ 0yeoj próbował, nadal nie działa – skycrew

+0

Jeśli przewinąć swoje komórki poza ekranem, prawda naprawić się podczas przewijania je z powrotem ? – stefandouganhyde

Odpowiedz

0

poniżej logika pracującego dla mnie:

ustawić szerokość równą szerokości UIView komórek.

Ex: container.frame.size.width = cell.frame.size.width

Powiązane problemy