Last active
August 23, 2016 08:25
-
-
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
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 | |
class ScalingConstraint: NSLayoutConstraint { | |
override var constant: CGFloat { | |
get { | |
return super.constant / UIScreen.mainScreen().scale | |
} | |
set { | |
super.constant = newValue | |
} | |
} | |
} |
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/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