如何绘制像粉笔一样的线?

lee*_*hou 3 iphone line draw ios

我想画线,就像粉笔一样.线条边缘微弱.就像在黑板上用粉笔画画一样.

我怎么得到这个?现在,我使用图像画线,但它看起来不像是在黑板上画画,因为线条并不暗淡.拜托,给我一些建议.

这是我的代码:

    for (NSDictionary *dictStroke in self.arrayStrokes)
    {
        NSArray *arrayPointsInstroke = [dictStroke objectForKey:@"points"];
        //UIColor *color = [dictStroke objectForKey:@"color"];

    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"point.png"]];

        float size = [[dictStroke objectForKey:@"size"] floatValue];
        [color setStroke];      // equivalent to both setFill and setStroke

        // draw the stroke, line by line, with rounded joints
        UIBezierPath* pathLines = [UIBezierPath bezierPath];
        CGPoint pointStart = CGPointFromString([arrayPointsInstroke objectAtIndex:0]);
        [pathLines moveToPoint:pointStart];
        for (int i = 0; i < (arrayPointsInstroke.count - 1); i++)
        {
            CGPoint pointNext = CGPointFromString([arrayPointsInstroke objectAtIndex:i+1]);
            [pathLines addLineToPoint:pointNext];
        }
        pathLines.lineWidth = size;
        pathLines.lineJoinStyle = kCGLineJoinRound;
        pathLines.lineCapStyle = kCGLineCapRound;
        [pathLines stroke];

        arraynum++;
    }
Run Code Online (Sandbox Code Playgroud)

Vee*_*Raj 6

尝试使用带斑马线的图案图像.这会给你像粉笔写作的效果.

brushPattern = [[UIColor alloc]initWithPatternImage: [UIImage imageNamed:@"pattern.jpg"]];

- (void)drawRect:(CGRect)rect
{
    [brushPattern setStroke];
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; // myPath - points to be drawn    
}
Run Code Online (Sandbox Code Playgroud)