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