Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagimaru/47002e03c10b4548bfc0 to your computer and use it in GitHub Desktop.
Save usagimaru/47002e03c10b4548bfc0 to your computer and use it in GitHub Desktop.
Drawing 1px lines on iOS Device with Retina Display

UIView

幅1pxの横線または縦線を描画する場合。

// 線幅
CGFloat wide = 1.0f / [UIScreen mainScreen].scale;

UIView *horizontal = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, wide)];

UIView *vertical = [[UIView alloc] initWithFrame:CGRectMake(0, 0, wide, 100)];

CALayer

幅1pxの枠線を描画する場合。 borderWidth は CGFloat なので0.5とかでも受け付ける。

// 線幅
CGFloat wide = 1.0f / [UIScreen mainScreen].scale;

CALayer *layer = [[CALayer alloc] init];
layer.borderWidth = wide;

Especially iOS 7.0 and later devices with Retina Display

CGFloat wide = 1.0f; // 1pt

// iOS 7.0以降のRetinaに限り、1pxにする
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
	wide /= [UIScreen mainScreen].scale;
}

OSバージョン判定用に SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO() を使用している。

http://stackoverflow.com/questions/3339722/how-to-check-ios-version/5337804#5337804

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