ios - 在 Swift 中将 PaintCode 代码插入 UIImageView

标签 ios swift uiimageview uibezierpath paintcode

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

在我的 Storyboard上,我有一个名为 exampleImageViewUIImageView,我想显示 PaintCode 代码并能够像矢量图形一样缩放不同大小的结果图像,例如1x、2.5x 5x 等(即平滑的非像素化线条和曲线)。

问题:

1 - 如何在 Xcode 中名为 exampleImageViewUIImageView 中将以下代码显示为图像?

2 - 如何在 Xcode 中名为 exampleViewUIView 中显示以下代码?

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 - How do I display the below code as an image in an UIImageView named exampleImageView?

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

2 - Is it possible to scale up or down the below code (i.e. like a vector graphic), and if so, how?

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

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

关于ios - 在 Swift 中将 PaintCode 代码插入 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35816700/

相关文章:

ios - 如何让SKSpriteNode不旋转纹理

iphone - iOS:UIButton titleLabel——它能做什么吗?

swift - 我正在尝试检测 ARKit SceneKit 中两个节点之间的接触

ios - defer 函数在 Swift 2.0 中不起作用

ios - 在 segue 上移动图像以加载到另一个 UIImageView

ios - 从自定义 UITableViewHeaderFooterView 获取 tableView

ios - 如何从 3 个 8 位灰度图像创建 RGB CIImage?

ios - 交互式推送通知操作按钮单击不起作用

ios - UIScrollView 自动以双倍大小启动

ios - 如何为条形按钮项目实现图像和文本