开发者

Grab the width and height of a device

I am using this code:

CGRect myRect = CGRectMake(self.frame.size.width, self.frame.size.height);开发者_JAVA技巧

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?


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);


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];


Use

CGRect myRect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.heigh);

And if you want to know the device screen size, then you should use:

[UIScreen mainScreen].bounds
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜