iOS: Best way to make a UIScrollView with dynamic height?

后端 未结 2 1932
悲&欢浪女
悲&欢浪女 2021-01-27 00:31

I\'m currently setting up a UIScrollView with the following structure

UIScrollView
--ContentView (UIView)
  --ContainerView1 (UIView)
     --UILabel1
     --UILa         


        
2条回答
  •  粉色の甜心
    2021-01-27 00:37

    //use the below code to set the content size of a scroll view.

        float newHeight=0.0f;
            for(UIView *subViews in [scrollViewObj subviews])
            {
                if([subViews isKindOfClass:[UIView class]])
                {
                    newHeight=newHeight+(subViews.frame.origin.x+subViews.frame.size.height);
                }
            }
            NSLog(@"%f",newHeight);
            [scrollView setContentSize:CGSizeMake(300, newHeight)];//change the width as you need
    

提交回复
热议问题