Roymunson Roymunson - 5 months ago 16
iOS Question

IOS self.view.frame.width equals 0

I am making a custom keyboard. In order to determine the orientation of some buttons I need to find the width of the keyboard. I do this by using:

self.view.frame.width


in my
viewDidLoad()
method.

However, it returns 0.

Answer

this can happen in two scenarios 1- you didn't set the size of the self.view (somehow ... if you created that view programmatically..)

2- if you didn't initialize that view at all ...

However if the keyboard width equals the viewcontroller width , you can use this code bekow:

CGFloat width = [UIScreen mainScreen].bounds.size.width;

Comments