【发布时间】:2012-10-14 02:21:15
【问题描述】:
我想在 UIView 的 drawRect 方法中绘制一条非常细的细线宽度。我看到的 CGContextSetLineWidth 值为 0.5 的线与用于绘制边框 CALayer 的 1.0 宽度值不匹配。
您可以看到两者之间的区别 - 红色线(宽度 = 1)比紫色/蓝色线(宽度 = 0.5)细很多。
这是我绘制伪 1.0 宽度水平线的方式:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextSetLineWidth(ctx, 0.5); // I expected a very thin line
CGContextMoveToPoint(ctx, 0, y);
CGContextAddLineToPoint(ctx, self.bounds.size.width, y);
CGContextStrokePath(ctx);
这是同一个视图的边框,这次使用 1.0 边框宽度:
UIView *myView = (UIView *)self;
CALayer *layer = myView.layer;
layer.borderColor = [UIColor redColor].CGColor;
layer.borderWidth = 1.0;
我需要做些什么不同的事情来绘制我自己的与 CALayer 版本宽度相同的自定义线?
【问题讨论】:
标签: ios ios5 core-graphics ios6 drawrect