title: Drawing a ruler in iOS - accurate 1 cm on screen - how to draw lines 1 mm apart?
body: <p>I am trying to draw a ruler, for any available iOS device, with accurate 1mm distances between start of lines/ticks. Usually i would get the PPI and calculate my distance of the pixels. Using Objective-C, it does not seem to work this way.</p>
  
  <p><code>linesDist</code> should contain my 1mm distance in "screen coordinate pixels".</p>
  
  <p><strong>Any ideas, how i can achieve this?</strong> </p>
  
  <p>my basic code looks like this: RulerView.m, which is a UIView:</p>
  
  <pre><code>-(void)drawRect:(CGRect)rect
  {
      [[UIColor blackColor] setFill];
  
      float linesDist = 3.0; // 1mm * ppi ??
  
      float linesWidthShort = 15.0;
      float linesWidthLong = 20.0;
  
      for (NSInteger i = 0, count = 0; i &lt;= self.bounds.size.height; i = i + linesDist, count++)
      {
          bool isLong = (int)i % 5 == 0;
  
          float linesWidth = isLong ? linesWidthLong : linesWidthShort;
          UIRectFill( (CGRect){0, i, linesWidth, 1} );
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>
  ppi detect (really ugly), based on the answer below:</p>
  
  <pre><code>float ppi = 0;
  switch ((int)[UIScreen mainScreen].bounds.size.height) {
      case 568: // iPhone 5*
      case 667: // iPhone 6
          ppi = 163.0;
          break;
  
      case 736: // iPhone 6+
          ppi = 154.0;
          break;
  
      default:
          return;
          break;
  }
  </code></pre>