将PaintCode代码插入Swift中的UIImageView

时间:2016-03-05 16:34:05

标签: ios swift uiimageview uibezierpath paint-code

我正在尝试使用PaintCode。例如,我导入了一个抽象的Illustrator图形文件,它生成了下面的bezier Swift代码。

在我的故事板上,我有一个名为UIImageView的{​​{1}}我希望显示PaintCode代码,并且能够像不同大小的矢量图形那样缩放结果图像,例如1x,2.5x 5x等(即平滑的非像素化线条和曲线)。

问题:

1 - 如何将以下代码显示为Xcode中名为exampleImageView的{​​{1}}中的图像?

2 - 如何在Xcode中的UIView exampleView中显示以下代码?

3 - 可以放大或缩小下面的代码(例如矢量图形),如果是这样,Xcode中的内容如何?

预期图片

enter image description here

PaintCode代码:

//// General Declarations
let context = UIGraphicsGetCurrentContext()

//// Color Declarations
let fillColor = UIColor(red: 0.087, green: 0.086, blue: 0.083, alpha: 1.000)

//// Group 2
CGContextSaveGState(context)
CGContextSetAlpha(context, 0.75)
CGContextBeginTransparencyLayer(context, nil)


//// Bezier Drawing
let bezierPath = UIBezierPath()
bezierPath.moveToPoint(CGPointMake(26.08, 23.65))
bezierPath.addCurveToPoint(CGPointMake(61.71, 12.5), controlPoint1: CGPointMake(38.43, 23.65), controlPoint2: CGPointMake(54.42, 18.61))
bezierPath.addCurveToPoint(CGPointMake(52.65, 1.35), controlPoint1: CGPointMake(69, 6.38), controlPoint2: CGPointMake(64.99, 1.35))
bezierPath.addCurveToPoint(CGPointMake(16.91, 12.5), controlPoint1: CGPointMake(40.2, 1.35), controlPoint2: CGPointMake(24.2, 6.38))
bezierPath.addCurveToPoint(CGPointMake(26.08, 23.65), controlPoint1: CGPointMake(9.63, 18.61), controlPoint2: CGPointMake(13.63, 23.65))
bezierPath.closePath()
bezierPath.moveToPoint(CGPointMake(48.14, 25))
bezierPath.addLineToPoint(CGPointMake(0.79, 25))
bezierPath.addCurveToPoint(CGPointMake(0.24, 24.35), controlPoint1: CGPointMake(-0.02, 25), controlPoint2: CGPointMake(-0.21, 24.73))
bezierPath.addCurveToPoint(CGPointMake(2.41, 23.65), controlPoint1: CGPointMake(0.76, 23.92), controlPoint2: CGPointMake(1.59, 23.65))
bezierPath.moveToPoint(CGPointMake(14.36, 12.5))
bezierPath.addCurveToPoint(CGPointMake(54.26, 0), controlPoint1: CGPointMake(22.62, 5.57), controlPoint2: CGPointMake(40.59, 0))
bezierPath.addCurveToPoint(CGPointMake(64.36, 12.5), controlPoint1: CGPointMake(67.93, 0), controlPoint2: CGPointMake(72.62, 5.57))
bezierPath.addCurveToPoint(CGPointMake(37.3, 23.65), controlPoint1: CGPointMake(58.56, 17.37), controlPoint2: CGPointMake(47.81, 21.59))
bezierPath.addLineToPoint(CGPointMake(49.75, 23.65))
fillColor.setFill()
bezierPath.fill()


CGContextEndTransparencyLayer(context)
CGContextRestoreGState(context)

1 个答案:

答案 0 :(得分:1)

  

1 - 如何在名为exampleImageView的UIImageView中将以下代码显示为图像?

可以在PaintCode中创建图像,但我认为它不适合这里。对于初学者,在PaintCode中创建绘图方法。

  

2 - 是否可以放大或缩小以下代码(例如矢量图形),若然,如何?

在PaintCode中,您可以使用框架使事物可以调整大小。

查看解决这两个问题的Dynamic Shapes tutorial