想要重绘的话,仅仅创建一个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()