Skip to content

Instantly share code, notes, and snippets.

@krin-san
Last active August 23, 2016 08:25
Show Gist options
  • Save krin-san/c2137094f432d144409b642f225fd51a to your computer and use it in GitHub Desktop.
Save krin-san/c2137094f432d144409b642f225fd51a to your computer and use it in GitHub Desktop.
NSLayoutConstraint with UIScreen scaling. Comes useful for a the thin separator views to be a 1px width on any screen
import UIKit
class ScalingConstraint: NSLayoutConstraint {
override var constant: CGFloat {
get {
return super.constant / UIScreen.mainScreen().scale
}
set {
super.constant = newValue
}
}
}
#import <UIKit/UIKit.h>
/// Allows to use a 1px wide delimiter views
@interface ScalingConstraint : NSLayoutConstraint
@end
@implementation ScalingConstraint
- (CGFloat)constant {
return [super constant] / [UIScreen mainScreen].scale;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment