Last active
August 29, 2015 14:22
-
-
Save ashchan/fb73e30d471ba5188890 to your computer and use it in GitHub Desktop.
Draw a half pixel horizontal line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// How to use | |
// Drag an UIView to storyboard, set constraints. | |
// Set the height constraint priority to less than 1000. | |
// The view will override that to half pixel. | |
class HairlineView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
required init(coder decoder: NSCoder) { | |
super.init(coder: decoder) | |
} | |
override func updateConstraints() { | |
let height = (1.0 / UIScreen.mainScreen().scale) | |
addConstraint(NSLayoutConstraint(item: self, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: height)) | |
super.updateConstraints() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment