Skip to content

Instantly share code, notes, and snippets.

@ashchan
Last active August 29, 2015 14:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashchan/fb73e30d471ba5188890 to your computer and use it in GitHub Desktop.
Save ashchan/fb73e30d471ba5188890 to your computer and use it in GitHub Desktop.
Draw a half pixel horizontal line
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