When you stroke a path, the stroke straddles the path. To say it another way, the path lies along the center of the stroke.
If the path runs along the edge between two pixels, then the stroke will (partially) cover the pixels on both sides of that edge. With a line width of 0.5, a horizontal stroke will extend 0.25 points into the pixel above the path, and 0.25 points into the pixel below the path.
You need to move your path so it doesn't run along the edge of the pixels:
CGFloat lineWidth = 0.5f;
CGContextSetLineWidth(ctx, lineWidth);
// Move the path down by half of the line width so it doesn't straddle pixels.
CGContextMoveToPoint(ctx, 0, y + lineWidth * 0.5f);
CGContextAddLineToPoint(ctx, self.bounds.size.width, y + lineWidth * 0.5f);
But since you're just drawing a horizontal line, it's simpler to use CGContextFillRect
:
CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextFillRect(ctx, CGRectMake(0, y, self.bounds.size.width, 0.5f));
In the python websocket-client you can indeed pass custom headers easily - there's a keyword argument header
available for this; see the following example from the docs:
conn = create_connection("ws://echo.websocket.org/", header={"User-Agent": "MyProgram"})
Edit: Keyword should be header
, not headers
.
Best Answer
Swift extension method (combined from AechoLiu answer below):
Objective-C:
Also calling out @FarrasDoko comment to try changing
borderWidth
tolineWidth
andborderColor
tostrokeColor
.