KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to draw double colored line with 1px lines of 2 different colors. I have a lot of code so I'm putting it after trying to explain. If I use uiview drawRect method it works fine when I switch off antialiasing but when I use layer's drawLayerInContext it either displays one plain line, or 2 plain line lines of 2px with antialiasing off or two half transparent lines of 2px with antialising on. I managed to get a similar behavior than UIView's drawRect method by creating an image with a custom context where I can specify a scale: UIGraphicsBeginImageContextWithOptions([self bounds].size, NO, 0.f); // 0.f for scale means "scale for device's main screen". I would just like to know why I don't get the same behavior in drawInContext and if there was a way to get similar behavior. Here is the code that draws the double color line: void DRAW_DOUBLE_LINE(CGContextRef ctx, CGPoint startPoint, CGPoint endPoint, UIColor* topColor, UIColor* bottomColor) { UIGraphicsPushContext(ctx); UIBezierPath *topLine = [[UIBezierPath alloc] init]; CGPoint topLineStartPoint = startPoint; CGPoint topLineEndPoint = endPoint; [topLine moveToPoint:topLineStartPoint]; [topLine addLineToPoint:topLineEndPoint]; [topColor setStroke]; topLine.lineWidth = 0.5; [topLine stroke]; UIBezierPath *bottomLine = [[UIBezierPath alloc] init]; CGPoint bottomLineStartPoint = topLineStartPoint; bottomLineStartPoint.y +=0.5; CGPoint bottomLineEndPoint = topLineEndPoint; bottomLineEndPoint.y +=0.5; [bottomLine moveToPoint:bottomLineStartPoint]; [bottomLine addLineToPoint:bottomLineEndPoint]; [bottomColor setStroke]; bottomLine.lineWidth = 0.5; [bottomLine stroke]; UIGraphicsPopContext(); } With the drawRect method of UIView I obtain this: | Points y coordinate | A
Tags (comma-separated)
Save Edits
Cancel