gpt4 book ai didi

ios - 使用 Playgrounds 在 Swift 中使用 UIBezierPath

转载 作者:搜寻专家 更新时间:2023-10-30 23:01:54 25 4
gpt4 key购买 nike

我是否必须创建自定义类才能在 Swift Playground 中使用 BezierPath?

下面的代码只显示黑色背景:

import UIKit
import XCPlayground

class GraphView : UIView {

override func drawRect(rect: CGRect) {

let path = UIBezierPath(rect: rect)
path.moveToPoint(CGPointMake(0,0))
path.addLineToPoint(CGPointMake(50,100))
path.closePath()
UIColor.redColor().setFill()

path.stroke()
}

}


let graphView = GraphView(frame: CGRectMake(0,0,960,640))

最佳答案

您必须在代码末尾使用它:

XCPlaygroundPage.currentPage.liveView = graphView

并打开 Playground 的“Assistant Editor”查看结果。

还要更改 View 的背景颜色,因为它是黑色的...而且您的线条也是黑色的。 ;)

关于ios - 使用 Playgrounds 在 Swift 中使用 UIBezierPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36989336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com