Adding a dynamically sized view (height) to a UIScrollView with Auto Layout

后端 未结 2 1605
深忆病人
深忆病人 2021-01-07 06:41

Here is my structure of views for this detail view (blogging application, I want to view the entire post which has dynamic height inside of a scrollview):

UI         


        
2条回答
  •  难免孤独
    2021-01-07 07:05

    in auto layout

    frame of scrollview is decided by constraints between scrollview and superview of scrollview. contentSize of scrollview is decided by constraints between scrollview and subview of scrollview.

    you should set the size of singlePostView. ScrollView calculate contentSize from it. (you need to add size constraints explicitly)

    CGFloat heightOfSinglePostView = calculate..
    [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[singlePost(heightOfSinglePostView)]|" options:0 metrics: 0 views:viewsDictionary]];
    

提交回复
热议问题