Aboodnet Aboodnet - 1 year ago 109
Swift Question

Modifying all subviews except for one

I have many subview elements under a single view which contain buttons, labels, ...etc. Please take a quick look at the below screenshot.

When I click a button I want all subviews disappear/hide except for the first subview which is UIImageView containning the background image.

How can I achieve that?


Answer Source

Given a parent view

let viewContainer : UIView = ...

you can hide all the children views but the ones of type UIImageView

viewContainer.subviews.forEach {
    if $0 is UIImageView == false { $0.isHidden }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download