2017-02-07 54 views

回答

1

這可能是如下

import UIKit 

class Rectangle:UIView{ 

    override func draw(_ rect: CGRect) { 
     let path = UIBezierPath(rect: rect) 
     path.move(to: CGPoint(x:0,y:rect.height)) 
     path.addLine(to: CGPoint(x:rect.width/2,y:rect.height/1.4)) 
     path.addLine(to: CGPoint(x:rect.width,y:rect.height)) 
     UIColor.red.setStroke() 
     path.stroke() 
    } 

} 

let rect=Rectangle(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) 
+0

謝謝你,但你可以請你給我的目標C一樣簡單? – hd1344

相關問題