skip to Main Content

I am using uiKit framework.
I am using stack view and inside that are buttons, and data of that buttons is coming from server. I want that when i receive data, first button in stack view will be selected by defalut and the color changes.
can anyone help please?

2

Answers


  1. // When you got data from URL request
    
    if let _button = stackView.arrangedSubviews.first as? YourButtonClass {
        _button.isSelected = true // or your custom logic,..
    }
    
    Login or Signup to reply.
  2. You need to get the first view that is a UIButton and then set his selected property to true

    DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
            if let button = self?.stackview.arrangedSubviews.first(where: { $0 is UIButton }) as? UIButton {
                button.isSelected = true
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search