首页 > 解决方案 > 如何正确地将单独的文件添加到 Xcode 项目中?

问题描述

我从事的唯一其他项目不需要额外的文件。我正在尝试按照本教程进行操作,但自动填充只是偶尔发生。我想我错误地向项目添加了一个新文件。

这是我为添加文件所做的工作。

YouTube 视频:https ://www.youtube.com/watch?v=YcDBMMjj0wU&t=199s

代码:

import UIKit

class DrawExamples: UIView {

    override func drawRect(rect: CGRect) {
        // context is the object used for drawing
        let context = UIGraphicsGetCurrentContext()
        CGContextSetLineWidth(context, 3.0)
        CGContextSetStrokeColorWithColor(context, UIColor.purpleColor().CGColor)

        /*
        //straight line
        CGContextMoveToPoint(context, 30, 30)
        CGContextAddLineToPoint(context, 150, 320)
        */

        CGContextMoveToPoint(context, 50, 50)
        CGContextAddLineToPoint(context, 90, 130)
        CGContextAddLineToPoint(context, 180, 100)
        CGContextAddLineToPoint(context, 90, 60)
        CGContextAddLineToPoint(context, 90, 130)


        //Actually draw the path
        CGContextStrokePath(context)

    }
}

截屏

标签: swift

解决方案


推荐阅读