So I got UIView
at the top of my app and I want to draw a thin line at the bottom of it, a very similar line that act as a seperator in UITableView
. I currently have a UIView
that has height of 1px set in IB, but when I compare that line to the seperator in UITableView
it has higher height. Is there any good way to draw a thin line inside a UIView
?
Give the frame of your line view a height
(or width
) of 0.5
and set the backgroundColor
to [UIColor lightGrayColor]
.
Edit: For non-retina you might change the height/width to (1.0 / [UIScreen mainScreen].scale)
This will result in 0.5 on retina and 1.0 on non-retina displays.
Just insert inside your UIView
#import <QuartzCore/QuartzCore.h>
and inside drawRect:
add this and specify the height of the line
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0f);
//start at this point
CGContextMoveToPoint(context, 0, self.frame.size.height);
//draw to this point
CGContextAddLineToPoint(context,
self.frame.size.width,
self.frame.size.height);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// and now draw the Path!
CGContextStrokePath(context);
}
and you'll get a line like the red one here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With