Roymunson Roymunson - 1 year ago 120
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:


in my

However, it returns 0.

Answer Source

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;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download