wufoo
wufoo

Reputation: 14611

how to change height of uiview defined in storyboard

Update: I ended up implementing the code below into it's own method and then called it from viewDidLayoutSubviews and willAnimateRotationToInterfaceOrientation. Doing it from viewDidAppear (as suggested) would not resize the view when returning from a segue.


I have a UIView defined in a storyboard which I'm using for a header view on my UIViewController. I have a constant in my code for all header views to be 80 units high. I have a tag on the storyboard header view of 200. I thought I could use this tag to get the view, modify the height of the underlying CGRect, and then re-set the header view to the modified CGRect. That doesn't seem to affect the height however. What am I missing?

- (void)viewDidLoad
{
   UIView *header = [self.view viewWithTag:200];
   CGRect hrect = [header frame];
   hrect.size.height = HEADER_HEIGHT;
   [header setFrame:hrect];
 ...

Upvotes: 0

Views: 2159

Answers (2)

LuisCien
LuisCien

Reputation: 6432

The problem is that you're using the tag as an NSString. The tag property is an NSInteger. Try doing the following:

- (void)viewDidLoad
{
    UIView *header = [self.view viewWithTag:200];// give the tag as an int
    CGRect hrect = [header frame];
    hrect.size.height = HEADER_HEIGHT;
    [header setFrame:hrect];
...

Also, make sure the tag you defined in the Storyboard is also 200 and not @"200".

Hope this helps!

Upvotes: 1

artud2000
artud2000

Reputation: 544

Try to do that on viewDidAppear then call

[self setNeedsLayout]

Upvotes: 3

Related Questions