0

I have a picker view and when a user picks a certain value from picker view I want to hide certain textviews and labels together:

[label1] [----textview1----]

[label2] [----textview2----]

[label3] [----textview3----]

so what I want is:

if (picker value is equal to "someValue")
{
 - hide label 2 and textview 2
 - shift label 3 and text view 3 to be positioned below label 1 and textview1
}

I tried this solution where I change priorities and this solution also but still no luck. I need to hide the label and textview together at once.

Community
  • 1
  • 1
u_kami
  • 565
  • 12
  • 28

3 Answers3

0

It depends on how your views are laid out. I would suggest 2 approaches:

1) Wrap each pair of textView + label in a wrapperView. Make an IBOutlet to a height constraint of every wrapper viewView. Then you can hide rows like this:

wrapperView2HeightConstraint.constant = 0;
[wrapperView2 layoutIfNeeded];

You might need to set wrapperView1.clipsSubviews = YES; so subviews are actually hidden.

2) The other approach is just to use UITableView and put each pair in a UITableViewCell. Then you can easily manipulate which cells are hidden on [tableView reloadData];. There's even a built in animation for that.

NKorotkov
  • 3,591
  • 1
  • 24
  • 38
0

Set constraints like this

Then what it looks like in gif

Code Keep 3 property

@property (weak, nonatomic) IBOutlet UILabel *secondLabel;
@property (weak, nonatomic) IBOutlet UITextField *secondTextfield;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *toChangeConstraint;

Then hide

  self.secondLabel.hidden = true;
self.secondTextfield.hidden = true;
self.toChangeConstraint.constant = -20;
[UIView animateWithDuration:0.5 animations:^{
    [self.view layoutIfNeeded];
}];

Then outlet constraint is this one

Leo
  • 24,596
  • 11
  • 71
  • 92
0

How about you set tag of textField and Label as textfield's tag tobe started out with 1,2,and soon and Label tag to be set as 51,52 and so on . so that they've a diff of 50 b/w them. and you can set them label.hidden and textview.hidden

Misha
  • 685
  • 8
  • 20