I have several view parameters saved in Core Data scaled to fit within self.view
. When I fetch the view parameters I want to rescale the views to fit within a smaller parent view (newView
). How do I get the viewSelected
subviews to resize within the newView
parent view?
newView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
newView.autoresizesSubviews = YES;
for (Shape *shape in shapes) {
ShapeView *viewSelected = [[SquareView alloc]init];
[viewSelected setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth];
viewSelected.frame = CGRectMake(shape.x,shape.y,shape.shapeSize,shape.shapeSize);
[newView addSubview:viewSelected];
}
[self.view addSubview:newView];
There are probably multiple ways of handling this, but I can think of two off of the top of my head.
Manually - What the autoresizing mask gives you is deterministic, so calculate it out.
Create an intermediate UIView that is the size of self.view, add your fetched views to it, and resize the intermediate view to the size of the "new smaller parent". Then your subviews will have resized appropriately. Then remove them from the intermediate view and add them to the desired destination view.