Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone: Get current view dimensions or screen dimensions

Hello i want to get the width and height of my main view. I want the correct value in landscape or portrait mode. I've tried the following:

   NSLog(@"aaa %f", [UIScreen mainScreen].applicationFrame.size.width);   NSLog(@"zzz %f", self.view.frame.size.width); 

These give 300 in landscape and 320 in portrait mode, yes it is larger in portrait mode. So.. my view takes up the whole screen (- status bar) so I expect 480 in landscape mode and 320 in portrait mode. What happened to the rest of the pixels. Do I have to hardcode these values? Thanks.

like image 267
gyozo kudor Avatar asked Jan 06 '11 11:01

gyozo kudor


People also ask

How do I find the dimensions of my screen?

The size of a desktop computer monitor is determined by physically measuring the screen. Using a measuring tape, start at the top-left corner and pull it diagonally to the bottom-right corner. Be sure to only measure the screen; do not include the bezel (the plastic edge) around the screen.

How do I find out the size of my screen on my phone?

1. Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size.

How do I find my screen size in Swift UI?

main. bounds. height I get the main screen width and height which is constant. So based on the situation you can use any of these two solutions.


2 Answers

Do either of the following lines work for you?

[[UIScreen mainScreen] bounds].size.height [[UIScreen mainScreen] bounds].size.width 

I suppose you can subtract the height of the status bar? Maybe i'm not understanding your question

like image 186
Omar Avatar answered Sep 21 '22 01:09

Omar


Try this :

UIWindow* window = [UIApplication sharedApplication].keyWindow; NSLog(@"%f",window.frame.size.width); 
like image 32
jithinroy Avatar answered Sep 19 '22 01:09

jithinroy