I\'m reimplementig some kind of UISplitViewController
. Now I need to draw a separator line between the master and the detail view. Now I have some questions for
If you need to add a true one pixel line, don't fool with an image. It's almost impossible. Just use this:
@interface UILine : UIView
@end
@implementation UILine
- (void)awakeFromNib {
CGFloat sortaPixel = 1 / [UIScreen mainScreen].scale;
// recall, the following...
// CGFloat sortaPixel = 1 / self.contentScaleFactor;
// ...does NOT work when loading from storyboard!
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, sortaPixel)];
line.userInteractionEnabled = NO;
line.backgroundColor = self.backgroundColor;
line.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:line];
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = NO;
}
@end
How to use:
Actually in storyboard, simply make a UIView that is in the exact place, and exact width, you want. (Feel free to use constraints/autolayout as normal.)
Make the view say five pixels high, simply so you can see it clearly, while working.
Make the top of the UIView exactly where you want the single-pixel line. Make the UIView the desired color of the line.
Change the class to UILine
. At run time, it will draw a perfect single-pixel line in the exact location on all devices.
(For a vertical line class, simply modify the CGRectMake.)
Hope it helps!