Как нарисовать несколько UIBezierPath разными цветами в UIView

Я хотел бы нарисовать несколько UIBezierPath в UIView с разным цветом обводки и заливки.

Вот код

- (void)drawRect:(CGRect)rect {

    context = UIGraphicsGetCurrentContext();

    [[UIColor grayColor] setFill]; 
    [[UIColor greenColor] setStroke];

    UIBezierPath *aPath = [[UIBezierPath alloc] init]; 
    [aPath moveToPoint:CGPointMake(227,34.25)];
    [aPath addLineToPoint:CGPointMake(298.25,34.75)];
    [aPath addLineToPoint:CGPointMake(298.5,82.5)];
    [aPath addLineToPoint:CGPointMake(251,83)];
    [aPath addLineToPoint:CGPointMake(251,67.5)];
    [aPath addLineToPoint:CGPointMake(227.25,66.75)];   
    [aPath closePath]; 
    aPath.lineWidth = 2;
    [aPath fill]; 
    [aPath stroke];

    UIBezierPath *aPath2 = [[UIBezierPath alloc] init];
    [aPath2 moveToPoint:CGPointMake(251.25,90.5)];
    [aPath2 addLineToPoint:CGPointMake(250.75,83.25)];
    [aPath2 addLineToPoint:CGPointMake(298.5,83)];
    [aPath2 addLineToPoint:CGPointMake(298.5,90.25)];
    [aPath2 closePath];
    aPath2.lineWidth = 2;
    [aPath2 fill]; 
    [aPath2 stroke];
    [paths addObject:aPath2];

Проблема в том, что обводка и цвет заливки установлены на текущем контекст. Можно ли нарисовать разные UIBezierPath с разными цветами в одном и том же CGContextRef?

Или мне нужно нарисовать каждый UIBezierPath в отдельном UIView?

10
задан Cœur 5 September 2018 в 10:16
поделиться