user2621075 user2621075 - 1 year ago 73
iOS Question

Hide Multiple UILabels At Once

I have about 20 UILabels that I'd like to set hidden at once. I know it can be done setting an IB Outlet to each label then calling labelOne.hidden = YES; for each UILabel but I would think there has to be a better way.

I tried setting each UILabel to one IB Outlet Collection but you can not call hidden on the Outlet Collection. Any Suggestions?

Rob Rob
Answer Source

A couple of options:

  1. You can set hidden:

    [self.labelsCollection setValue:@true forKey:@"hidden"];

    Note, that's @true/@false, not true/false.

  2. You can also iterate through your outlet collection:

    for (UILabel *label in self.labelsCollection) {
        label.hidden = true;
  3. You can make these subviews of some UIView and then hide that parent view.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download