0
我使用CGContext
創建一個漏斗形狀,首先繪製一個三角形,然後是一條線。我在我的UIView
子類的drawRect
中實現了這一點,但是想知道是否有其他繪製方法,因爲這些線條有些模糊。有沒有比CGContext更好的選擇?
override func drawRect(rect: CGRect) {
let context: CGContextRef = UIGraphicsGetCurrentContext()!
CGContextClearRect(context, rect);
let rectWidth: CGFloat = 15
// Line
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1)
CGContextMoveToPoint(context, rectWidth/2, 5)
CGContextAddLineToPoint(context, rectWidth/2, 10)
CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
CGContextSetLineCap(context, CGLineCap.Round)
CGContextSetLineWidth(context, 3.0)
CGContextStrokePath(context)
// Triangle
CGContextBeginPath(context);
CGContextMoveToPoint (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(context, CGRectGetMidX(rect), 8);
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMinY(rect));
CGContextClosePath(context);
UIColor.blueColor().setFill()
CGContextFillPath(context);
}
但是,當我輸入我設計的圖像,圖像更清晰(你可以告訴在iPhone上):
那麼,有沒有一個更好的方式來實現這個輸出? CGContext
行有點模糊,所以我想知道是否有更好的選擇,以及這些方法的優點和缺點。
我看到兩個圖像同樣模糊。 – Tricertops