【问题标题】:UIBezierpath filling custom shapeUIBezierpath 填充自定义形状
【发布时间】:2014-04-10 01:28:27
【问题描述】:

我试图填充这个形状。但是使用我的代码,它会填充整个视图,而不是内部形状。

https://www.dropbox.com/s/nplglh39xyvn1cr/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202014-04-10%2010.21.04.png

UIBezierPath *shape = [UIBezierPath bezierPathWithRect:self.bounds];

[shape moveToPoint:CGPointMake(self.bounds.size.width*0.15, self.bounds.size.height*0.6)];

[shape addCurveToPoint:CGPointMake(self.bounds.size.width*0.85, self.bounds.size.height*0.4)
         controlPoint1:CGPointMake(self.bounds.size.width*0.1, self.bounds.size.height*0.3)
         controlPoint2:CGPointMake(self.bounds.size.width*0.6, self.bounds.size.height*0.5)];

[shape addCurveToPoint:CGPointMake(self.bounds.size.width*0.15, self.bounds.size.height*0.6)
         controlPoint1:CGPointMake(self.bounds.size.width*0.9, self.bounds.size.height*0.7)
         controlPoint2:CGPointMake(self.bounds.size.width*0.4, self.bounds.size.height*0.5)];
[shape closePath];
[[UIColor blueColor] setFill];
[shape fill];
[[UIColor brownColor] setStroke];
[shape stroke];

有什么问题?当我画三角形或任何其他形状时,它可以完美地工作。

【问题讨论】:

    标签: ios objective-c uiview drawing uibezierpath


    【解决方案1】:
    UIBezierPath *shape = [UIBezierPath bezierPathWithRect:self.bounds];
    

    这就是问题所在。您正在创建具有视图边界的路径。请改用UIBezierPath *shape = [[UIBezierPath alloc] init];

    【讨论】:

      【解决方案2】:

      试试这个:

      我想你只会得到那个形状......

      UIBezierPath *shape = [[UIBezierPath alloc] init];
      
      [shape moveToPoint:CGPointMake(45,78)];
      
      [shape addCurveToPoint:CGPointMake(67,51)
               controlPoint1:CGPointMake(43,78)
               controlPoint2:CGPointMake(55,54)];
      
      [shape addCurveToPoint:CGPointMake(144,45)
               controlPoint1:CGPointMake(80,49)
               controlPoint2:CGPointMake(137,60)];
      
      [shape addCurveToPoint:CGPointMake(143,77)
               controlPoint1:CGPointMake(157,34)
               controlPoint2:CGPointMake(143,77)];
      
      [shape addCurveToPoint:CGPointMake(43,84)
               controlPoint1:CGPointMake(143,77)
               controlPoint2:CGPointMake(43,65)];
      
      [shape addCurveToPoint:CGPointMake(43,78)
               controlPoint1:CGPointMake(43,103)
               controlPoint2:CGPointMake(43,78)];
      [shape closePath];
      [[UIColor blueColor] setFill];
      [shape fill];
      [[UIColor brownColor] setStroke];
      shape.lineWidth = 1;
      [shape stroke];
      

      改变 CGPoint 取决于你的形状....


      如果还有更多的困惑,试试这个工具并通过绘制形状来获取你的代码......

      工具名称:PaintCode (http://www.paintcodeapp.com/)

      下载链接http://www.paintcodeapp.com/wp-content/uploads/2013/10/paintcode-trial-1-3-3.zip

      【讨论】:

        猜你喜欢
        • 2011-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-16
        相关资源
        最近更新 更多