iterate through objects using their tag swift

I don’t like working with tags, but you can do something like this:

for tag in 0 ..< 75 {
    let taggedView = view.viewWithTag(tag)
    switch taggedView {
    case let label as UILabel:
        label.textAlignment = .center
    case let button as UIButton:
        button.backgroundColor = UIColor.blue
    default:
        print("could not cast view")
    }
}

Just cast the view to each specific type, like UILabel or UIButton.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top