Neo Z
Neo Z

Reputation: 47

iOS:use the frame constrained by Auto Layout to create a subview

I create a view called boundView using IB and Auto Layout,then in the controller I call [self.boundView layoutIfNeeded],then I pass self.boundView.frame.size to a method to generate the size of boundView's subview CardView. And then use the

 PlayingCardView *playingCardView = [[PlayingCardView alloc]initWithFrame:frame];

to create subview programmatically. I do use NSLog to check that the size of subview is smaller than superview. But when I use [self.boundView addSubview:CardView] to add the subview. It is larger than superview! Is there something wrong with the coordinate?Or it is because I combine the Auto Layout with the view I create by code?

Upvotes: 0

Views: 109

Answers (1)

pajevic
pajevic

Reputation: 4657

Where are you doing this? If it is in viewDidLoad then the autolayout sizes will not have been calculated yet. Try doing it in viewDidLayoutSubviews.

Upvotes: 1

Related Questions