2015-06-15 11 views
6

Ho riscontrato problemi con i vincoli di layout automatico in UITableViewCell quando si utilizza UIBezierPath. La mia cella non andrà a tutta larghezza. Puoi vedere le differenze tra Immagine 1 e Immagine 2. Immagine 2 Non ho aggiunto angoli di arrotondamento.UITableViewCell Larghezza layout automatico non funzionante con UIBezierPath

Immagine 1 With UIBezierPath

Immagine 2 Without UIBezierPath

In precedenza, sto avendo lo stesso problema con UIBezierPath in UIView (potete vedere i primi 2 UIView con "0") . La soluzione che sto utilizzando è quello di mascherare gli angoli di arrotondamento nel viewDidLayoutSubviews come qui di seguito i codici: -

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

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

Ma ora mi sono bloccato in UITableViewCell perché io posso aggiungere gli angoli di arrotondamento in viewDidLayoutSubviews. I miei codici come di seguito: -

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

cerco di aggiungere [cell.contentView layoutIfNeeded]; ma ancora lo stesso.

Qualsiasi aiuto sarebbe apprezzato.

+0

'container.layer.masksToBounds = YES;' o '-clipsToBounds' – 0yeoj

+0

@ 0yeoj provato, non funziona ancora – skycrew

+0

Se si scorre le cellule fuori campo, fa si fissano quando li si scorre indietro ? – stefandouganhyde

risposta

0

sotto logica di funzionamento per me:

impostare la larghezza UIView uguale alla larghezza della cella.

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

Problemi correlati