Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios中使用bezier路径制作星形?_Ios_Objective C_Swift_Drawing_Uibezierpath - Fatal编程技术网

如何在ios中使用bezier路径制作星形?

如何在ios中使用bezier路径制作星形?,ios,objective-c,swift,drawing,uibezierpath,Ios,Objective C,Swift,Drawing,Uibezierpath,我正在使用贝塞尔路径制作简单的形状。使用贝塞尔路径制作星形的过程是什么?我想这就是您要寻找的: func starPathInRect(rect: CGRect) -> UIBezierPath { let path = UIBezierPath() let starExtrusion:CGFloat = 30.0 let center = CGPointMake(rect.width / 2.0, rect.height / 2.0) let poi

我正在使用贝塞尔路径制作简单的形状。使用贝塞尔路径制作星形的过程是什么?

我想这就是您要寻找的:

func starPathInRect(rect: CGRect) -> UIBezierPath {
    let path = UIBezierPath()

    let starExtrusion:CGFloat = 30.0

    let center = CGPointMake(rect.width / 2.0, rect.height / 2.0)

    let pointsOnStar = 5 + arc4random() % 10

    var angle:CGFloat = -CGFloat(M_PI / 2.0)
    let angleIncrement = CGFloat(M_PI * 2.0 / Double(pointsOnStar))
    let radius = rect.width / 2.0

    var firstPoint = true

    for i in 1...pointsOnStar {

        let point = pointFrom(angle, radius: radius, offset: center)
        let nextPoint = pointFrom(angle + angleIncrement, radius: radius, offset: center)
        let midPoint = pointFrom(angle + angleIncrement / 2.0, radius: starExtrusion, offset: center)

        if firstPoint {
            firstPoint = false
            path.moveToPoint(point)
        }

        path.addLineToPoint(midPoint)
        path.addLineToPoint(nextPoint)

        angle += angleIncrement
    }

    path.closePath()

    return path
}
此函数可让您决定在星图中需要多少点

查看此项了解更多详细说明


希望这有帮助。:)如果有任何疑问,请告诉我

我想这就是你想要的:

func starPathInRect(rect: CGRect) -> UIBezierPath {
    let path = UIBezierPath()

    let starExtrusion:CGFloat = 30.0

    let center = CGPointMake(rect.width / 2.0, rect.height / 2.0)

    let pointsOnStar = 5 + arc4random() % 10

    var angle:CGFloat = -CGFloat(M_PI / 2.0)
    let angleIncrement = CGFloat(M_PI * 2.0 / Double(pointsOnStar))
    let radius = rect.width / 2.0

    var firstPoint = true

    for i in 1...pointsOnStar {

        let point = pointFrom(angle, radius: radius, offset: center)
        let nextPoint = pointFrom(angle + angleIncrement, radius: radius, offset: center)
        let midPoint = pointFrom(angle + angleIncrement / 2.0, radius: starExtrusion, offset: center)

        if firstPoint {
            firstPoint = false
            path.moveToPoint(point)
        }

        path.addLineToPoint(midPoint)
        path.addLineToPoint(nextPoint)

        angle += angleIncrement
    }

    path.closePath()

    return path
}
此函数可让您决定在星图中需要多少点

查看此项了解更多详细说明

希望这有帮助。:)如果有任何疑问,请告诉我

尝试以下路径:

//// Star Drawing
UIBezierPath* starPath = [UIBezierPath bezierPath];
[starPath moveToPoint: CGPointMake(45.25, 0)];
[starPath addLineToPoint: CGPointMake(61.13, 23)];
[starPath addLineToPoint: CGPointMake(88.29, 30.75)];
[starPath addLineToPoint: CGPointMake(70.95, 52.71)];
[starPath addLineToPoint: CGPointMake(71.85, 80.5)];
[starPath addLineToPoint: CGPointMake(45.25, 71.07)];
[starPath addLineToPoint: CGPointMake(18.65, 80.5)];
[starPath addLineToPoint: CGPointMake(19.55, 52.71)];
[starPath addLineToPoint: CGPointMake(2.21, 30.75)];
[starPath addLineToPoint: CGPointMake(29.37, 23)];
[starPath closePath];
[UIColor.redColor setStroke];
starPath.lineWidth = 1;
[starPath stroke];
您可以使用应用程序为iOS和OSX绘制形状。 这是一款易于使用且非常有用的应用程序

快乐编码。

尝试以下路径:

//// Star Drawing
UIBezierPath* starPath = [UIBezierPath bezierPath];
[starPath moveToPoint: CGPointMake(45.25, 0)];
[starPath addLineToPoint: CGPointMake(61.13, 23)];
[starPath addLineToPoint: CGPointMake(88.29, 30.75)];
[starPath addLineToPoint: CGPointMake(70.95, 52.71)];
[starPath addLineToPoint: CGPointMake(71.85, 80.5)];
[starPath addLineToPoint: CGPointMake(45.25, 71.07)];
[starPath addLineToPoint: CGPointMake(18.65, 80.5)];
[starPath addLineToPoint: CGPointMake(19.55, 52.71)];
[starPath addLineToPoint: CGPointMake(2.21, 30.75)];
[starPath addLineToPoint: CGPointMake(29.37, 23)];
[starPath closePath];
[UIColor.redColor setStroke];
starPath.lineWidth = 1;
[starPath stroke];
您可以使用应用程序为iOS和OSX绘制形状。 这是一款易于使用且非常有用的应用程序


快乐编码。

你能不能把它做大一点。你能不能把它做大一点。参见上的示例参见上的示例