4
4

More than 5 years have passed since last update.

Quartz2Dでむっちゃ細い線を書く

Last updated at Posted at 2013-10-12

こんな感じで細い線を書こうとしても、色が薄くなるだけで細い線を書いてくれない。

CGContextSetLineWidth(ctx, 0.5f);
CGContextSetStrokeColorWithColor(ctx, [UIColor alloc] blackColor].CGColor);
CGContextMoveToPoint(ctx, 10, 0);
CGContextAddLineToPoint(ctx, 10, 100);
CGContextStrokePath(ctx);

そういうときは、線の太さの半分だけずらす。

CGFloat lineWidth = 0.5f;
CGContextSetLineWidth(ctx, lineWidth);
CGContextSetStrokeColorWithColor(ctx, [UIColor alloc] blackColor].CGColor);

CGContextMoveToPoint(ctx, 10+lineWidth*0.5, 0);
CGContextAddLineToPoint(ctx, 10+lineWidth*0.5, 100);
CGContextStrokePath(ctx);

マジかよって感じ。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4