LoginSignup
28
26

More than 5 years have passed since last update.

Retina Display 環境で幅1pxの線を描画する

Last updated at Posted at 2014-03-10

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;

iOS 7.0以降の 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() を使用している。

28
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
26