Note, I'm looking to make a 1px line, not a 1pt line. Meaning it should be 1px regardless of screen scale (so 0.5pt on Retina devices).
I can do this programmatically, but can I do it in the Interface Builder? For example I cannot set a UIView to have a height of less than 1.
If I can do it in IB then I don't have to declare an outlet and manually set the frame in awakeFromNib
.
With xCode 6 and introduction of
@IBInspectable
and@IBDesignable
keywords it is definitely possible and rather simple. No need to subclass/outlet anything.You can do an extension (category) for NSLayoutConstraint with following code (swift):
Then you can choose needed constraint in your IB.
Go to it's properties and set the value.
In above case it will render a view with 1 px height on 1x, 2x and 3x devices.
You can do it in .xib file. Just edit it as text and set constant="0.5" instead of "1" in your view height constraint
In Interface Builder
Seems that it is not possible, one must do it programmatically or build a custom view.
Based on @Nevs12 's answer and it's comments, I think it makes more sense to use such thing: