Last active
October 29, 2018 07:40
-
-
Save Arthraim/92ca42a9abdc0eeb9ad7 to your computer and use it in GitHub Desktop.
Hairline of iOS
This file contains 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
/** | |
* Width of hairline (1px on real device screen) | |
* The dppx of screens can be found here http://dpi.lv/ | |
* | |
* @return CGFloat number to be set for "1px" | |
*/ | |
+ (CGFloat)hairLineWidth { | |
if ([UIScreen mainScreen].bounds.size.width == 414.f) { // Plus | |
return 1.f / 2.46f; // 2.46 is the dppx of plus screens | |
} else { | |
return 1.f / [UIScreen mainScreen].scale; // for other screens, dppx is just as same as scale | |
} | |
} |
This file contains 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
// Swift 4 version | |
/// Width of hairline (1px on real device screen), the dppx of screens can be found here http://dpi.lv/ | |
var hairLineWidth: CGFloat { | |
if UIScreen.main.bounds.width == 414 { // plus | |
return 1.0 / 2.46 // 2.46 is the dppx of plus screens | |
} else { | |
return 1.0 / UIScreen.main.scale // for other screens, dppx is just as same as scale | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
看不下去了 必须star