katit
katit

Reputation: 17915

How to draw 1px line using BezierPath

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?

Upvotes: 0

Views: 504

Answers (1)

SebastianCrow
SebastianCrow

Reputation: 46

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;

Upvotes: 1

Related Questions