0

I have following code to draw horizontal line:

UIBezierPath *topLine = [UIBezierPath bezierPath];
    [topLine moveToPoint:CGPointMake(0, topMargin + lineHeight * 2.0f)];
    [[self getTopSeparatorLineColor] setStroke];
    topLine.lineWidth = 1.0f;
    [topLine addLineToPoint:CGPointMake(rect.size.width, topMargin + lineHeight * 2.0f)];
    [topLine stroke];

It works, but line is "fat". I want to draw line just like UITableView separator..

Is it possible with UIBezierPath?

katit
  • 17,375
  • 35
  • 128
  • 256
  • Perhaps `0.5`? A `lineWidth` of `1.0f` is (on retina devices) two pixels wide. – Rob Sep 04 '14 at 15:53
  • Doesn't make any difference – katit Sep 04 '14 at 15:58
  • Should have made _some_ difference. lol. 0.25f? – Rob Sep 04 '14 at 17:05
  • 0.25f looks better, but I want to know how to make this properly without guessing numbers.. – katit Sep 04 '14 at 17:07
  • I guess if I have to use "magic" number - I need to know how to determine what this number is. Perhaps using some kind of API to get conversion? – katit Sep 04 '14 at 17:13
  • If you want it to be identical, you might want to specify no separator, and then [draw your own](http://stackoverflow.com/questions/1374990/how-to-customize-tableview-separator-in-iphone), and then you can ensure that both the separator and your new line are identically rendered. – Rob Sep 04 '14 at 17:13

1 Answers1

1

As Apple UIBezierPath Class Reference says:

@property(nonatomic) CGFloat lineWidth

The line width defines the thickness of the receiver's stroked path. A width of 0 is interpreted as the thinnest line that can be rendered on a particular device.

So simply do it and you will always get 1px width:

topLine.lineWidth = 0.0f;
  • Had to take answer away. Just tried this - line not drawn at all. Not in Simulator, not on real device – katit Sep 04 '14 at 21:00
  • Sure. I've got no chance to try it on my own yesterday but I remember that it worked in the past... Apple official reference lies at now? – SebastianCrow Sep 05 '14 at 05:40
  • Seems like it does. Or my eyes lying, they don't see the line :) – katit Sep 05 '14 at 16:25