2012-06-12 4 views
5

Sto cercando di arrotondare solo gli angoli in alto a destra e sinistra della mia tableview. Sto usando il codice qui sotto e sembra solo di essere arrotondamento alto a sinistra ...Come arrotondare solo gli angoli su un UITableView?

CAShapeLayer *topLayer = [CAShapeLayer layer]; 
UIBezierPath *roundedPath = 
[UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(9.f, 9.0f)];  
topLayer.path = [roundedPath CGPath]; 
+0

http: // StackOverflow .com/a/5826698/855738 Ho usato questa risposta per fare più o meno la stessa cosa – BBog

+1

Sappi che è un vecchio post, ma assicurati di averlo. [tableView.layer setMasksToBound: YES] e dovrebbe essere bello e dandy –

+0

Vedere la risposta accettata [qui] [1]. Potrebbe essere lo stesso problema. [1]: http://stackoverflow.com/questions/26934231/uiview-in-cell-cant-round-right-hand-corners –

risposta

2

Spero che questo funzionerà. Trova le migliori percorsi d'angolo per creare un livello maschera

UIBezierPath *PathToMask; 
PathToMask = [UIBezierPath bezierPathWithRoundedRect:self.testView.bounds 
           byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) 
             cornerRadii:CGSizeMake(8.0, 8.0)]; 

Creare una maschera di livello forma utilizzando l'UIBezierPath maskPath

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 
maskLayer.frame =self.testView.bounds; 
maskLayer.path = PathToMask.CGPath; 

impostare il livello maschera maskLayer

self.testView.layer.mask = maskLayer;