xcode simulator iphone screen size - ios

I put this code in my app:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
NSLog(#"screenWidth : %f", screenWidth);
NSLog(#"screenHeight : %f", screenHeight);
The I start the simulator with Iphone 3.5 inch.
The log prints 320.000000 for the width.
However, when I then change the device for the simulator, selecing 4inch, it stills shows the same width. Why? Whats wrong. It is supposed to be 640 px in width for Iphone 4 and above, doesnt it?

In the simulator screenWidth will be always 320 ( right now iphone4-5 ). You can check the scale with [[UIScreen mainScreen] scale];
scale will be 2.0 if you running on retina iPhone.

According to the Apple Docs, that value is the "default logical value". If you want to know the actual size, take a look at [[UIScreen mainScreen] scale]. For retina devices, this value is 2.0, so do [[UIScreen mainScreen] bounds].size.width * [[UIScreen mainScreen] scale]

no the width is always 320 POINTS / DPIs -- what you mean is that it really has 640 PIXELS (which are device dependant)
Calculations are always based on device INDEPENDENT points
UIScreen offers a scalingFactor that translates dpi <> pixels

Related

How to find View frame for IPhone 5 and IPhone 6 and IPhone 6+

I have an application where I am adding one view with certain frame programmatically, it is okay for iphone4 (320 * 480) but How can I calculate frame size for IPhone5 and IPhone6 resolutions with given autoresizingmask value , Thanks in Advance.
To create programmatically you can use screen bounds to calculate size of the device
CGRect screenRect = [[UIScreen mainScreen] bounds];
screenRect.size.height == 667 width = 375// iphone6
screenRect.size.height == 736 width 414 // iphone 6+
screenRect.size.height == 568 width 320 // iphone 5
I forgot to give autoresizing mask. Adding that fixed it.

Custom view with CGRectMake location x and y providing incorrect view

Previous i am using Xcode 6.4 or below, In that I didn't notify this type issues. but now I am getting noticeable problems in Xcode 7.2 in related CGRectMake x,y Position.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
UIView *smallView=[[UIView alloc]initWithFrame:CGRectMake(screenWidth/2, screenHeight/2, 100, 100)];
smallView.backgroundColor=[UIColor redColor];
[self.view addSubview:smallView];
NSLog(#"%f",smallView.frame.origin.x);// 137.500000
above snip code, the position of x & y not perfect. the below image is output .
but if i add center=self.view.ceter It will come to center. the output is
smallView.center=self.view.center;
the problem is , in both case x & y position values same ,
NSLog(#"%f\n%f\n%f\f%f ",screenWidth/2,screenHeight/2,self.view.center.x,self.view.center.y);
Why they will show different result, how can i do without using center property. or Shall go for Autolayout .

How to get iOS device screen height and width [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
IPhone/IPad: How to get screen width programmatically?
How to get orientation-dependent height and width of the screen?
Accounting for the various iOS devices and orientations, what is the simplest approach to getting the current screen resolution, including height and width?
UIScreen is your friend here.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.
Hope it helps you..

Screen width and height

I want to get the width and height of the screen, with this code ...
float screenWidth = [UIScreen mainScreen].bounds.size.width;
float screenHeight = [UIScreen mainScreen].bounds.size.height;
NSLog(#"%f %f",screenWidth, screenHeight);
I get always 320 480 , but these aren't the true measures of the simulator. Now I'm testing on a retina simulator with more resolution, but i always get 320 480
I think your answer can be found here: in iPhone App How to detect the screen resolution of the device
Its the scale that interests you as well. Use CGFloat screenScale = [[UIScreen mainScreen] scale]; to find out the scale.
When positioning elements your points should always be in non-retina scale. Size of the screen for 3.5 inch is 320x480 units and 320x568 for the 4 inch screen. The pixel resolution is times two for retina screens.

Monotouch Ipad3 retina cannot run in full resolution

What do I need to do to run in full resolution? No matter what I do,
UIScreen.MainContent.Bounds => {1024x768}
I am running Monodevelop 2.8.8.4 and I am setting my Deployment Target to 5.1
Any Ideas?
Thanks
Can't verify this since I don't have an iPad3, but on iPhone4's retina display bounds does not tell the whole story.
You need to take scale into consideration too;
CGRect bounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize realSize =
CGSizeMake(bounds.size.width * scale, bounds.size.height * scale);
That would most likely translate to multiplying width and height by UIScreen.MainScreen.Scale on MonoTouch.

Resources