Skip to content

Instantly share code, notes, and snippets.

@Arthraim
Last active October 29, 2018 07:40
Show Gist options
  • Save Arthraim/92ca42a9abdc0eeb9ad7 to your computer and use it in GitHub Desktop.
Save Arthraim/92ca42a9abdc0eeb9ad7 to your computer and use it in GitHub Desktop.
Hairline of iOS
/**
* 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
}
}
// 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
}
}
@mcfans
Copy link

mcfans commented Oct 29, 2018

看不下去了 必须star

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment