简体   繁体   中英

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM