I'm trying to combine a border on an UIView with a line drawn in drawRect. I use for both the same width. But the problem is that sometimes the resulting width of the lines drawn is the same for both and sometimes not - this even changes with device orientation! But even without changing the device orientation it's in general still not the same width.
The border is drawn with:
view.layer.borderColor = [UIColor blackColor].CGColor;
view.layer.borderWidth = 1.0f;
Above that view is another view, which is a subclass of UIView. Both views have the same width and this second view covers the above view's top. The covering view uses the following code in drawRect to draw a line on the left, which is supposed to align perfectly with the border of the above view below it:
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat x = self.bounds.origin.x;
CGFloat y = self.bounds.origin.y;
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
// Left line
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x, height);
CGContextStrokePath(context);
// Right line
CGContextMoveToPoint(context, width - 1.0f, y);
CGContextAddLineToPoint(context, width - 1.0f, height);
CGContextStrokePath(context);
Any ideas how this can be achieved? Right now, even though the width is always 1.0f, it's just coincidence if both lines are drawn with the same visible width.
The goal is to end up with something that looks like a view with rounded corners on the bottom but usual edges on the top. That's why I'm doing this. The first view has the rounded corners and the second view above it matches it in width but covers the top part, so the rounded cornes on the top are not visible.
Screenshot in portrait:
Screenshot in landscape:
The yellow view is above the white view. The white view's black lines are drawn as a result of view.layer.borderWidth = 1.0f. The black lines to the left and right of the yellow view are drawn in drawRect with the code above. Orientation changes trigger a redraw but the drawing code itself remains the same. Both screenshots are from an iPhone with retina display (iPhone 4S).
As far as I can tell all values are "integers":
x: 0.000000, y: 0.000000
width: 264.000000, height: 10.000000
frame.origin.x: 33.000000, frame.origin.y: 38.000000