Aboodnet Aboodnet - 8 days ago 6
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?

none

Answer

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 }
}
Comments