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).
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.