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.

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


Try this :

UIWindow* window = [UIApplication sharedApplication].keyWindow;
NSLog(@"%f",window.frame.size.width);

Useful macros that will give you the correct size based on the device orientation:

#define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)
#define SCREEN_HEIGHT ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width)

Need Your Help

Multiple background images IE8

jquery css internet-explorer jquery-plugins internet-explorer-8

Is there any jquery plugin (or any other way) to force IE8 to show multiple background images?

HTTP Status 404 - on Eclipse with Tomcat

eclipse servlets tomcat7

I am trying just to run a servlet on my local Tomcat with Eclipse.