我有一个CASHAPELAYer, 我用它来绘制条形图中的小点。 问题在于这些点在视网膜显示器上都太大了。 我已经设置了内容比例表, 并检查了它是否已经设置了 。 但我还是看不出它与它有什么区别!
CAShapeLayer *lineShapeLayer = [CAShapeLayer layer];
lineShapeLayer.contentsScale = [[UIScreen mainScreen] scale];
CGMutablePathRef path = CGPathCreateMutable();
lineShapeLayer.backgroundColor = [UIColor clearColor].CGColor;
lineShapeLayer.bounds = CGRectMake(0, 0, self.backgroundLayer.bounds.size.width, 1.5);
lineShapeLayer.anchorPoint = CGPointMake(0, 0);
lineShapeLayer.position = CGPointMake(0, rint((self.verticalPartitionHeight)*i));
lineShapeLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithFloat:1], [NSNumber numberWithInt:2], nil];
lineShapeLayer.strokeColor = [UIColor blackColor].CGColor;
lineShapeLayer.lineWidth = 1;
NSLog(@"contentsScale: %f", lineShapeLayer.contentsScale);
CGPathMoveToPoint(path, nil, 0, .5);
CGPathAddLineToPoint(path, nil, lineShapeLayer.frame.size.width, .5);
[lineShapeLayer setPath:path];
[self.backgroundLayer addSublayer:lineShapeLayer];
Here is the view if I make it with PNGs:
Here is the view with the CAShapeLayer code (set to line width .5 even.):