这是图,上面的是用UIView,下面的使用CALayer。明显Layer上面有锯齿。这种个情况如何解决呢?
代码如下
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 10);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor);
CGContextBeginPath(ctx);
NSArray *xs = @[@(10),@(35),@(60),@(150),@(80)];
NSArray *ys = @[@(100),@(35),@(40),@(200),@(300)];
CGPoint previousCenter = CGPointZero;
for (NSUInteger i = 0; i < [xs count]; i++)
{
CGPoint start = previousCenter;
CGPoint end = CGPointMake([xs[i]floatValue], [ys[i]floatValue]);
if (i == 0) {
CGContextMoveToPoint(ctx, start.x, start.y);
}
CGContextAddLineToPoint(ctx, end.x, end.y);
previousCenter = end;
}
CGContextDrawPath(ctx, kCGPathStroke);
UIView是写在 drawRect:(CGRect)rect里面
CALayer是写在 drawInContext:(CGContextRef)ctx里面
Anda boleh menukarnya kepada CAshapleLayer berikut ialah kod imej untuk kesan membesarkan simulator iphone6 kepada 100
Tetapkan nilai di atas pada DrawLayer anda.
Nilai lalai atribut ini ialah 1.
Kod rujukan:
sublayer
lapisan