Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the frame of an UIView does not work

Tags:

I have a problem with the frame-property in iOS 7. I wanna resize some UIViews in the viewDidLoad-method of my UIViewController, but if I do it like int screenHeight = [[UIScreen mainScreen] bounds].size.height; [self.leftSideTableView setFrame: CGRectMake(0, 0, 320, screenHeight)]; the height is set as I want it till the end of the method, but in every other method it is as is has been before!

What's wrong with it or is it just a bug of the compiler or anything else?

like image 566
MyJBMe Avatar asked Aug 15 '13 23:08

MyJBMe


People also ask

What is frame in UIView?

Frame A view's frame ( CGRect ) is the position of its rectangle in the superview 's coordinate system. By default it starts at the top left. Bounds A view's bounds ( CGRect ) expresses a view rectangle in its own coordinate system.

How do I change the width of a view in Swift?

1) Control-drag from a frame view (e.g. questionFrame) to main View, in the pop-up select "Equal heights". 2)Then go to size inspector of the frame, click edit "Equal height to Superview" constraint, set the multiplier to 0.7 and hit return.

What is UIView in Swift?

The UIView class is a concrete class that you can instantiate and use to display a fixed background color. You can also subclass it to draw more sophisticated content.


2 Answers

One has to put view resizing into -viewDidLayoutSubviews:! (documentation)

Placing view frame changes into -viewWillAppear: or -viewDidLoad: will not work, because the views are not laying out yet!

like image 97
MyJBMe Avatar answered Nov 11 '22 12:11

MyJBMe


  • Check if you are using autolayout in your xib file. If you don't want to use autolayout, uncheck it in your xib file.

  • Change your self.leftSideTableView frame in -viewWillAppear:.

like image 44
liuyaodong Avatar answered Nov 11 '22 13:11

liuyaodong