0
votes

In a UIView inside the "-(void)drawRect:(CGRect)rect" method. I want to draw a plain black line (as a border), but I always get a semi-transparent line. Only the four points at the corners are perfectly black. Why is that?

Here is the mycode:

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAlpha(context,1.0);
CGContextSetRGBStrokeColor(context,0.0,0.0,0.0,1.0);
CGContextMoveToPoint(context,0.0,0.0);
CGContextAddLineToPoint(context,rect.size.width,0.0);
CGContextAddLineToPoint(context,rect.size.width,rect.size.height);
CGContextAddLineToPoint(context,0.0,rect.size.height);
CGContextClosePath(context);
CGContextStrokePath(context);
}
1

1 Answers

0
votes

If you want to add border to a UIView, you can do it as below as well

yourView.layer.borderColor = [UIColor blackColor].CGColor;
yourView.layer.borderWidth = 2.0f;

Don't forget to import QuartzCore framework.