0

I have this objective-c code to display a rectangle in the center of the screen:

modalView = [[UIView alloc] initWithFrame:CGRectMake(24, 404, 592, 353)]  
modalView.backgroundColor = [UIColor redColor];

The problem is that when I run it, the size of the rectangle and the location of the rectangle are off (note that this is an app extension, though I believe that shouldn't matter). This is what it looks like

I did some googling and came across self.view.contentScaleFactor. I printed this value out in the console and, although I was simulating an iPhone 5s which has a retina display, I consistently got 1.0 instead of 2.0. I proceeded to print [UIScreen mainScreen].scale and got 2.0, so I manually set self.view.contentScaleFactor = [UIScreen mainScreen].scale This didn't make a difference. I found that if I divide all the numbers in CGRectMake by 2 it works, but this isn't a very elegant solution. How else can I solve this? Why is this occurring?

Thanks in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

UIKit functions with points, not pixels. You don't need to scale anything up for Retina/Non-Retina.

Acey
  • 8,048
  • 4
  • 30
  • 46
  • Then why are all the sizes and coordinates off? – user1778698 Aug 10 '14 at 19:31
  • The screen size is 320x480 (or 320x568 for retina iPhones) points. All of your UIKit components are positioned in those points. Your rectangle should be something like (12, 200, 250, 175). Don't use any of those scale methods, you don't need them for this. – Acey Aug 10 '14 at 21:36