Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab the width and height of a device

Tags:

iphone

ipad

I am using this code:

CGRect myRect = CGRectMake(self.frame.size.width, self.frame.size.height);

But it gives this error:

- Property "frame" not found on object of type [myViewController]

Anyone have any ideas on how I should modify my code?

like image 856
Linuxmint Avatar asked Dec 04 '22 09:12

Linuxmint


2 Answers

First of all, you have too few arguments for the CGRectMake function. You need to define your origin. Also, you need to have self.view instead of just self. Looks something like this:

CGRect myRect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
like image 89
sudo rm -rf Avatar answered Dec 16 '22 05:12

sudo rm -rf


the view frame of the view from within the code is being executed

  CGRect myViewFrame = self.view.frame;

or the frame of the screen if that's what you want (says device in the title of the question)

CGRect screenFrame = [[UIScreen mainScreen] bounds];

or this which will return the same minus status bar if visible

CGRect actualyScreenFrame = [[UIScreen mainScreen] applicationFrame];
like image 21
Zaky German Avatar answered Dec 16 '22 04:12

Zaky German