Sanjay Mangaroliya
Sanjay Mangaroliya

Reputation: 4342

Remove white Space after hide views in scrollview?

I have UIScrollview with dynamic views(Label, Imageview) inside it. I hide some views but white blank space is there. how can I remove it?

I tried with below code but it doesn't work,

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]];

The layout of File Like:

-View

 -ScrollView

  -UIImageView

  -UIButton

  -UIButton

  -UILable

  -UILable

  -UIButton

  -UILable

  -UILable

Upvotes: 3

Views: 1968

Answers (1)

CrazyJoeLv
CrazyJoeLv

Reputation: 570

Just hiding views won't help, as it still will take place. You have several options: 1. Each of views inside scrollView should have height constraint that should be set to 0 when hiding is required. Then you should call

[scrollView setNeedsLayout];
[scrollView layoutIfNeeded];
  1. You can remove unneeded views from scrollView by calling

[viewToHide removeFromSuperview];

Upvotes: 1

Related Questions