2016-08-10 68 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