UIBezierPath Multiple Line Colors

前端 未结 2 1610
不知归路
不知归路 2020-12-03 12:58

My attempt to draw UIBezierPath lines with different colors is failing me. All the lines change to the currently selected color. All my path and information are all stored i

相关标签:
2条回答
  • 2020-12-03 13:13

    The stroke/fill colors only affect the -stroke command. They don't affect the -appendPath: command. Paths don't contain per-segment color information.

    If you need a multi-colored line you're going to need to stroke each color separately.

    0 讨论(0)
  • 2020-12-03 13:29

    Set your stroke color (and what have you), then stroke, and then move to the next path:

    - (void)drawRect:(CGRect)rect
    {
        for (int i = 0; i < [pathInfo count]; i++){
            NSArray *row = [[NSArray alloc] initWithArray:[pathInfo objectAtIndex:i]];
    
            NSLog(@"Path: %@",[row objectAtIndex:0]);
            NSLog(@"Color: %@",[row objectAtIndex:1]);
            NSLog(@"Width: %@",[row objectAtIndex:2]);
            NSLog(@"Type: %@",[row objectAtIndex:3]);
    
            UIBezierPath *path = [row objectAtIndex:0];
    
            path.lineCapStyle = kCGLineCapRound;
            path.miterLimit = 0;
    
            //width
            path.lineWidth = [[row objectAtIndex:2] floatValue];
    
            //color
            [[row objectAtIndex:1] setStroke];
    
            //path
            [path stroke];
        }
    
        UIBezierPath *path = [self pathForCurrentLine];
        if (path)
        {
            // set the width, color, etc, too, if you want
            [path stroke];
        }
    }
    
    0 讨论(0)
提交回复
热议问题