Screen width and height - ios

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.

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.

I disable autolayout, now my view size and screen size are 320 not the larger size

- (void)viewDidLoad {
[super viewDidLoad];
CGFloat starSize = [[UIScreen mainScreen] bounds].size.width / 5;;
NSLog(#"star size: %f", starSize);
I'm testing on an iPhone 6 Plus simulator and Star size is logging as 64. 64*5 = 320. My screen should be bigger than 320.
How do I get the correct screen size?
EDIT: I added launch images. My screen size is still 320.

iOS Capturing bigger image compared with camera preview mode iOS

for iPhone 6 and 6+ I used following code for stretching camera on full screen.
I basically stretch camera to full screen by using cameraViewTransform. Due to this I am getting more enlarged image compared with preview mode. How can I only capture only that part that is visible in preview mode.
Refer following screen shots for more clearance
In Iphone 6 -
(in preview mode)
(captured image)
In iphone 5 -
(in preview mode)
(captured image)
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
// set the aspect ratio of the camera
float heightRatio = 4.0f / 3.0f;
// calculate the height of the camera based on the screen width
float cameraHeight = screenSize.width * heightRatio;
// calculate the ratio that the camera height needs to be scaled by
float scale = screenSize.height / cameraHeight;
// move the controller to the center of the screen
self.imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0);
// concatenate the scale transform
self.imagePickerController.cameraViewTransform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, scale, scale);

xcode simulator iphone screen size

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

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

Resources