ios – 用平行线填充UIBezierPath

ios – 用平行线填充UIBezierPath,第1张

概述我正在尝试使用UIBezierPath绘制自定义形状: UIBezierPath *aPath = [UIBezierPath bezierPath]; [aPath moveToPoint:CGPointMake(100.0, 0.0)]; // Draw the lines. [aPath addLineToPoint:CGPointMake(200.0, 40.0 我正在尝试使用UIBezIErPath绘制自定义形状:

UIBezIErPath *aPath = [UIBezIErPath bezIErPath];    [aPath movetoPoint:CGPointMake(100.0,0.0)];    // Draw the lines.    [aPath addlinetoPoint:CGPointMake(200.0,40.0)];    [aPath addlinetoPoint:CGPointMake(160,140)];    [aPath addlinetoPoint:CGPointMake(40.0,140)];    [aPath addlinetoPoint:CGPointMake(0.0,40.0)];    [aPath closePath];

我想用平行线填充它以使其剥离.我也希望改变这条线的颜色.
假设我想让它们垂直.
我必须以规律的间隔计算这条路上的某些点,我该怎么做?

我发现这个UIcolor colorWithPatternImage然后我不能改变我的线条内部形状的颜色和“密度”.

@H_419_20@解决方法 像nikolai Ruhe所说,最好的选择是使用你的形状作为剪切路径,然后在形状的边界框内绘制一些图案.以下是代码外观的示例

- (voID)drawRect:(CGRect)rect{    // create a UIBezIErPath for the outline shape    UIBezIErPath *aPath = [UIBezIErPath bezIErPath];    [aPath movetoPoint:CGPointMake(100.0,0.0)];    [aPath addlinetoPoint:CGPointMake(200.0,40.0)];    [aPath closePath];    [aPath setlinewidth:10];    // get the bounding rectangle for the outline shape    CGRect bounds = aPath.bounds;    // create a UIBezIErPath for the fill pattern    UIBezIErPath *stripes = [UIBezIErPath bezIErPath];    for ( int x = 0; x < bounds.size.wIDth; x += 20 )    {        [stripes movetoPoint:CGPointMake( bounds.origin.x + x,bounds.origin.y )];        [stripes addlinetoPoint:CGPointMake( bounds.origin.x + x,bounds.origin.y + bounds.size.height )];    }    [stripes setlinewidth:10];    CGContextRef context = UIGraphicsGetCurrentContext();    // draw the fill pattern first,using the outline to clip    CGContextSaveGState( context );         // save the graphics state    [aPath addClip];                        // use the outline as the clipPing path    [[UIcolor bluecolor] set];              // blue color for vertical stripes    [stripes stroke];                       // draw the stripes    CGContextRestoreGState( context );      // restore the graphics state,removes the clipPing path    // draw the outline of the shape    [[UIcolor greencolor] set];             // green color for the outline    [aPath stroke];                         // draw the outline}
总结

以上是内存溢出为你收集整理的ios – 用平行线填充UIBezierPath全部内容,希望文章能够帮你解决ios – 用平行线填充UIBezierPath所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1012301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存