Label doesn't show all the text inside scrollView

前端 未结 4 1491
渐次进展
渐次进展 2021-01-03 15:18

I want the DecriptionLabel (the Lorem Ipsum one) to have all the text inside it visible. As you can see, it is getting trimmed.

The two buttons should b

相关标签:
4条回答
  • 2021-01-03 15:43

    Add the following constraint:

    scrollview.contentview.height >= safearea.height
    

    This may show an error in interface builder but works in my tests:

    To remove the design time error you could set a design time intrinsic content size for the scrollview's contentview (in my case I used the safe area's height of 554):

    Another option (without placeholder values in IB) is to create the following constraint...

    scrollview.contentview.height = safearea.height
    

    ... and change its priority to a value lower than the label's vertical content compression resistancy.

    0 讨论(0)
  • 2021-01-03 15:55

    You should add the following constraints: (following in sudo code)

    // Constraints for ScrollView
    scrollView.top = ViewController.view.top
    scrollView.leading = ViewController.view.leading
    scrollView.trailing = ViewController.view.trailing
    scrollView.bottom = ViewController.view.bottom
    
    // Constraints for View
    view.top = scrollView.top
    view.leading = scrollView.leading
    view.trailing = scrollView.trailing
    view.bottom = scrollView.bottom
    
    // Width of view
    view.width = ViewController.view.width
    

    Now you just need to make sure you have layout constraints for each child of the 'view' and it's height will be correct and display the full size of the textview.

    0 讨论(0)
  • 2021-01-03 16:04

    I was originally answering How to make button stick to bottom of scroll view if the content isn't large enough? but since it is marked as duplicate of this one I am posting my answer here. Please try to set your constraints the following way: https://imageshack.com/a/img923/6671/Txzu98.png
    The trick is that you set Button.Bottom Equal To ContainerView.Bottom with lower priority (I use 750) than Button.Top Greater Than Or Equal To Label.Bottom (Here I use default 1000)
    The Label has to have number of lines set to 0.
    The height of the button should be set by height constraint (in this case is 50).
    The Container View Height constraint should be with low priority (in this case 250)
    You should run the code to see actual result on device or simulator. Storyboard shows it a bit differently.

    For the current question: https://imageshack.com/a/img923/7276/tQeT0h.png
    The basic idea is the same.
    Button Down has the same constraints as Button from above answer without Button.Top Greater Than Or Equal To Label.Bottom.
    There should be fixed vertical constraint between Button Up and Button Down. I am setting Button Up with fixed Height and setting trailing and leading constraint equal to trailing and leading of Button Down.
    The constraint Button.Top Greater Than Or Equal To Label.Bottom is now Button Up.Top Greater Than Or Equal To Label.Bottom

    0 讨论(0)
  • 2021-01-03 16:04

    Have you set numberOfLines for label to 0 (that means autosize the label according to its text length)?

    0 讨论(0)
提交回复
热议问题