编辑代码

var myString = "Hello world!     -  swift.jsrun.net"
print(myString)//5.1初识图形世界
//5.1.2触摸事件



import UIKit

class CoreGraphUIView: UIView {

    override func touchesBegan (_touches: Set<UITouch>,with event: UIEvent?) {
        self.backgroundColor = UIColor.red
        print ("Began: \(touches) ")
    }

    override func touchesEnded (_touches: Set<UITouch>, with event: UIEvent?) {
        self. backgroundColor = UIColor.lightGray
        print ("Ended: \(touches) ")
    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
        self. backgroundColor = UIColor.blue
        print ("Moved: \ (touches) ")
    }
}

class ViewController: UIViewController{

    override func viewDidLoad () {
        super.viewDidLoad ()
        //Do any additional setup after loading the view.
        let height = self.view.frame.size.height
        let width = self.view.frame.size.width
        let graphFrame = CGRect (x: 0, y: 0, width: width,height: height)
        let graphView = CoreGraphUIView (frame: graphFrame)
        graphView.backgroundColor = UIColor.white
        self.view.addSubview (graphView)
    }
}


let touch:UITouch = touches.first! as UITouch
print(touch.location(in: view).x)
print(touch.location(in: view).y)



//5.2拥有自己的绘图类


class Shape {
    var name  : String?
    var sides  : Int?
    Val origin : CGPoint?
    var lineColor : UIColor = UICOLOr.red
    var filColor : UICOLOr = UrCoLor.green
    var linewiath : CGELoat = 2
    init (name: String, sides : Int, origin: CGPoint) {
        self. name = name
        self.sides = sides
        self.origin = origin
    }
    func sayhello () {
        print ( "Shape is \(name!), sides \(sides!), and originCord is (\(origin!.x), \(origin!.y))")
    }
}

//5.2.2实例化Shape类

Import UInit

class Shape {
    var name  : String?
    var sides : Int?
    var origin : CGPoint?
    var linecolor : UIColor = UICOlor.red
    var fillColor : UIColor = UIColor.green
    var lineWidth: CGFloat = 2
    init (name : String, sides : Int, origin、