//
// MyView.swift
// L01Test
//
// Created by robertkun on 15/9/7.
// Copyright (c) 2015 MAC. All rights reserved.
//
import UIKit
class MyView: UIView { var path = CGPathCreateMutable() // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func drawRect(rect: CGRect) { // Drawing code UIColor.redColor().set() var context = UIGraphicsGetCurrentContext() CGContextSetLineWidth(context, 5) CGContextAddPath(context, path) CGContextStrokePath(context) } override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { let p = (touches as NSSet).anyObject()?.locationInView(self) CGPathMoveToPoint(path, nil, p!.x, p!.y) } override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { let p = (touches as NSSet).anyObject()?.locationInView(self) CGPathAddLineToPoint(path, nil, p!.x, p!.y) setNeedsDisplay() } func drawTwoLines(point:CGPoint, lineJoin:CGLineJoin) { let context = UIGraphicsGetCurrentContext() CGContextSetLineJoin(context, lineJoin) CGContextSetLineWidth(context, 5) CGContextMoveToPoint(context, point.x-100, point.y+50) CGContextAddLineToPoint(context, point.x, point.y) CGContextAddLineToPoint(context, point.x+100, point.y+50) CGContextStrokePath(context) } }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164197.html原文链接:https://javaforall.cn