2016-08-10 70 views
4

我想以此来仅绘制圆角,你可以在我的截图中看到(图C)绘制差异

enter image description here

这里是绘制2 UIBezierPath(见截图)之间的差异我代码:

let context = UIGraphicsGetCurrentContext() 
CGContextSaveGState(context) 

let rectanglePath = UIBezierPath(rect: rect) 
CGContextAddPath(context, rectanglePath.CGPath) 
CGContextEOClip(context) 

let roundedRectanglePath = UIBezierPath(roundedRect: productRect, byRoundingCorners: roundedCorners, cornerRadii: CGSize(width: 6, height: 6)) 
CGContextAddPath(context, roundedRectanglePath.CGPath) 
CGContextFillPath(context) 

CGContextRestoreGState(context) 

不幸的是,它不起作用。我只画圆形的黑色矩形。

你有什么想法吗?

非常感谢。

回答

5

您可以使用一个路径:

let path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius) 
path.appendPath(UIBezierPath(rect: bounds)) 
path.usesEvenOddFillRule = true 

UIColor.blackColor().setFill() 
path.fill() 

或者你可以使用CoreGraphics中:

let path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius) 
path.appendPath(UIBezierPath(rect: bounds)) 

let context = UIGraphicsGetCurrentContext() 
CGContextAddPath(context, path.CGPath) 
CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor) 
CGContextEOFillPath(context) 

国债收益率:

enter image description here

+0

这是完美的!非常感谢Rob。 – thierryb