How to set a views frame width? (Why can't I set it directly?)

Kaibin picture Kaibin · May 22, 2012 · Viewed 11.4k times · Source

I want to reset a UIView's frame size so I wrote:

view.frame.size.width = x;

but it doesn't work, can anyone tell me why?

Answer

Saad picture Saad · May 22, 2012

you can't set width directly, do this

CGRect frm = view.frame;
frm.size.width = x;
view.frame = frm;