2017-05-04 2 views
-1

J'ai un UIView carré que je dois diviser en section transversale avec deux couleurs différentes comme le montre hereDiviser la place UIView en sections Cross iOS Objectif C

+0

Ajoutez un calque sur la vue et donnez-lui une couleur différente. Pour former votre couche, utilisez le chemin bezier. –

+0

pouvez-vous pls élaborer .. !!? –

+0

Prenez la référence de [ici] (http://stackoverflow.com/questions/21311880/drawing-uibezierpath-on-code-generated-uiview) –

Répondre

0

ici est mon code pour réaliser ce graphique:

//Define the drawing path 
UIBezierPath *path1 = [[UIBezierPath alloc] init]; 
//path Move to start drawing position 
[path1 moveToPoint:CGPointMake(200, 100)]; 
//Draw a straight line from the starting position to(100, 200) 
[path1 addLineToPoint:CGPointMake(100, 100)]; 
//To draw a line from (100, 200) to (200, 200) 
[path1 addLineToPoint:CGPointMake(100, 200)]; 
//close path 
[path1 closePath]; 

CAShapeLayer *layer1 = [[CAShapeLayer alloc] init]; 
layer1.path = path1.CGPath; 
layer1.fillColor = [UIColor colorWithRed:0.88 green:0.87 blue:0.87 alpha:1.0].CGColor; 
[self.view.layer addSublayer:layer1]; 

UIBezierPath *path2 = [[UIBezierPath alloc] init]; 
[path2 moveToPoint:CGPointMake(200, 100)]; 
[path2 addLineToPoint:CGPointMake(200, 200)]; 
[path2 addLineToPoint:CGPointMake(100, 200)]; 
[path2 closePath]; 

CAShapeLayer *layer2 = [[CAShapeLayer alloc] init]; 
layer2.path = path2.CGPath; 
layer2.fillColor = [UIColor colorWithRed:0.89 green:0.57 blue:0.53 alpha:1.0].CGColor; 
[self.view.layer addSublayer:layer2]; 

Voici le résultat: result image