How to draw a 1px line in storyBoard?

Xcode 9 Swift: You can add a thin seperator with 1px line in the Storyboard using UIView.

Under Size Inspector, Just set the height to 1, width example to 360.

enter image description here

Apple documentation on UIView.


This would help you if you're coding in Swift:

    func lineDraw(viewLi:UIView)
    {
            let border = CALayer()
            let width = CGFloat(1.0)
            border.borderColor = UIColor(red: 197/255, green: 197/255, blue: 197/255, alpha: 1.0).CGColor
            border.frame = CGRect(x: 0, y: viewLi.frame.size.height - width, width:  viewLi.frame.size.width, height: viewLi.frame.size.height)
            border.borderWidth = width
            viewLi.layer.addSublayer(border)
            viewLi.layer.masksToBounds = true
    }

I got your point too, finally I find way out.
As we know, if we draw a line and set the height by code, we can set the height equal to (1.0 / [UIScreen mainScreen].scale).
But here, you wanna to draw in storyboard.
My way is subclass UIView or UIImageView, based on your demand as OnePXLine. In OnePXLine class, override layoutSubviews like below:

- (void)layoutSubviews {
     [super layoutSubviews];
     CGRect rect = self.frame;
     rect.size.height = (1 / [UIScreen mainScreen].scale);
     self.frame = rect;
}

And you can draw 1 px line in storyboard by use this class.
Goodluck!

Tags:

Ios