WatchOS - setTextColor in background issue

Hi


I'm trying to set the textColor of a label in background but its not working, the same code works in foreground. In background only the text itself changes, the color stays the same. Can anyone else confirm this?


A few points:

- This is a workout app with workout session started

- Timer runs in background as expected

- textColor remains unchanged

- same code applies in foreground and textColor changes.

- code is being called at the right time but not reflected.

- changeLabel text gets called and applied as expected.


func changeLabels() {
     
        self.setTitle(routineName)
        RoutineStateLabel.setText(currentTimerDict["Stage"] as? String)
        CountDownLabel.setText(MakeTimeLabel(Int(timer)))
        timeRemainingLabel.setText(MakeTimeLabel(timeRemaining))
        timeElapsedLabel.setText(MakeTimeLabel(timeElapsed))
     
    }

    func changeStageLabelColor() {
     
        if let stage = currentTimerDict["Stage"] as? String {
         
            if stage == "Warm Up" {
             
                RoutineStateLabel.setTextColor(UIColor.yellowColor())
             
            } else if stage.rangeOfString("Round") != nil {
             
                RoutineStateLabel.setTextColor(UIColor.redColor())
             
            } else if stage.rangeOfString("Rest") != nil {
             
                RoutineStateLabel.setTextColor(UIColor.greenColor())
             
            } else if stage == "Cool Down" {
             
                RoutineStateLabel.setTextColor(UIColor.blueColor())
             
            } else if stage == "Quick Timer" {
             
                RoutineStateLabel.setTextColor(UIColor.orangeColor())
             
            } else {
             
                RoutineStateLabel.setTextColor(UIColor.greenColor())
            }
        }
    }

Accepted Reply

You can just set a boolean in didDeactivate method like needsTextColorUpdate = YES and in willActivate method, if needsTextColorUpdate == YES then set text color.

In my games I use a bool to store my timer's status in order to reschedule it (if scheduled) in willActivate.

Replies

By "background", are you referring to when your app isn't active? Such as when the screen is off? If so, you can't update the user interface in this state. The interface controller must be active in order for UI updates to be applied.

Hey @tom_witkin,


Any update on this? It seems users are also complaining that the timer itself stops when the watch goes to sleep. On the simulator I dont see that, the timer runs for me regardless of the state of the app.


Any feedback is highly appreciated

You can just set a boolean in didDeactivate method like needsTextColorUpdate = YES and in willActivate method, if needsTextColorUpdate == YES then set text color.

In my games I use a bool to store my timer's status in order to reschedule it (if scheduled) in willActivate.

Thanks for the response. yea I ended up checking in WillActiviate and udpating the label and color.


        if routineStarted == false {
          
            StopButtonPressed()
          
        } else {
          
            changeLabels()
            changeStageLabelColor()
        }