Reputation: 1703
I load a view from a nib, this view has several subviews,and are on the xib. Once I load this view from nib, I tried to change the subviews frame by using: view.subLabel.frame = CGRectMake(). However, this does not work and I do not know why. I disabled the autolayout property of the xib and it does not work as well. Anyone knows how to change views frame loaded from xibs? Thank you.
codes for init and change frame are as follows:
Init: GADNativeContentAdView *adView = [[[NSBundle mainBundle] loadNibNamed:@"loadingContent" owner:nil options:nil] firstObject];
Then change frame: adView.logoView.frame = CGRectMake(0, 0,50, 50);
but this does not work.
Upvotes: 0
Views: 1300
Reputation: 2797
try add the code:
[view setAutoresizesSubviews:NO];
Swift:
view.autoresizesSubviews = false
Upvotes: 0
Reputation: 20369
user2053760,
When you instantiate a view using
GADNativeContentAdView *adView = [[[NSBundle mainBundle] loadNibNamed:@"loadingContent" owner:nil options:nil] firstObject];
you havent specified its frame so by default it is instantiated with frame (0,0,0,0). Then you went on to change the view which is inside this adView and set its frame to (0,0,50,50).
How do you expect the subView to be visible if the view which holds it itself is of size (0,0) ???
so first change the parent frame as
adView.frame = CGRectMake(0, 0,50, 50);
then you can set the frame for childView,
adView.logoView.frame = CGRectMake(0, 0,50, 50);
Upvotes: 0
Reputation: 2176
You should work with NSAutolayout and use NSAutoLayoutConstraints if you want to change the size or position of your subviews. For example declare a height constraint as a property, connect it in your xib, and change it this way:
myHeightConstraint.constant = newValue
UIView.animateWithDuration(duration, animations: {
self.view.layoutIfNeeded()
})
Upvotes: 0