Calculate the contentsize of scrollview

前端 未结 7 1467
旧巷少年郎
旧巷少年郎 2020-12-13 11:40

I\'m having a scrollview as the detailedview of tableview cell. There are multiple views on the detailedview like labels, buttons etc. which I\'m creating through interface

7条回答
  •  隐瞒了意图╮
    2020-12-13 11:59

    You could try to use the scrollview'ers ContentSize. It worked for me and I had the same problem with the control using dynamic content.

        // Calculate scroll view size
    float sizeOfContent = 0;
    int i;
    for (i = 0; i < [myScrollView.subviews count]; i++) {
        UIView *view =[myScrollView.subviews objectAtIndex:i];
        sizeOfContent += view.frame.size.height;
    }
    
    // Set content size for scroll view
    myScrollView.contentSize = CGSizeMake(myScrollView.frame.size.width, sizeOfContent);
    

    I do this in the method called viewWillAppear in the controller for the view that holds the scrollview. It is the last thing i do before calling the viewDidLoad on the super.

    Hope it will solve your problem.

    //hannes

提交回复
热议问题