想要重繪的話,僅僅創建一個UIView的父類並且重載drawRect
override func drawRect(regionThatNeedsToBeDrawn: CGRect)
你可以在外面畫一個需要重繪的區域,但是他不是最優化的。
永遠不要調用drawRect!!
setNeedsDisplay()
setNeedsDisplayInRect(regionThatNeedsToBeRedrawn: CGRect)
IOS之後會在恰當的時間調用deawRect
Core Graphics Concepts
Create a UIBezierPath,畫三角形
let path = UIBezierPath()
Move around, add lines or arcs to the path
path.moveToPoint(CGPoint(80, 50)) // assume screen is 160x250
path.addLineToPoint(CGPoint(140, 150))
path.addLineToPoint(CGPoint(10, 150))
Close the path (if you want)
path.closePath()
Now that you have a path, set attributes and stroke/fill
// note this is a method in UIColor, not UIBezierPath
UIColor.greenColor().setFill()
// note this is a method in UIColor, not UIBezierPath
UIColor.redColor().setStroke()
// note this is a property in UIBezierPath, not UIColor
path.linewidth = 3.0
path.fill()
path.stroke()
//用UIBezierPath畫圓
let roundRect = UIBezierPath(roundedRect: aCGRect, cornerRadius: aCGFloat)
//用UIBezierPath畫橢圓
let oval = UIBezierPath(ovalInRect: aCGRect)
//畫圓角
addClip()