Making view resize to its parent when added with addSubview

后端 未结 6 640
再見小時候
再見小時候 2020-12-29 21:35

I\'m having a problem when using addSubview.

Example code:

ParentView *myParentView = [[ParentView alloc] initWithNibName:@\"ParentView \" bundle:nil         


        
6条回答
  •  孤独总比滥情好
    2020-12-29 22:31

    Just copy the parent view's frame to the child-view then add it. After that autoresizing will work. Actually you should only copy the size CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)

    childView.frame = CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height);
    [parentView addSubview:childView];
    

提交回复
热议问题