Changing Dark Mode Colors in Code

Playing with Dark Mode. Created Color Groups and assigned them to colors in objects. Works fine. However, when I try to change a color in code the app crashes in the simulator on the line where I do that. No Mobile Device crash logs generated.

Here’s the code in the Action event of an IOSButton. The Me.TextColor lines cause the crash. As I understand it, these lines aren’t related to the existing Color Groups. Ideas?

If Me.Caption = "?" Then Me.Caption = "X" Me.TextColor = ColorGroup.NamedColor("Red") HelpTextArea.Visible = True HelpSwitch.Visible = True HelpSwitchLabel.Visible = True Else Me.Caption = "?" Me.TextColor = ColorGroup.NamedColor("Dynamic Green") HelpTextArea.Visible = False HelpSwitch.Visible = False HelpSwitchLabel.Visible = False End If

Well first of all “Red” and “Dynamic Green” aren’t valid names. I suspect what you’re getting is an unhandledException.

Try “redColor” and “systemGreenColor” instead… and yes… case matters.

You can get the valid names from Apple’s docs…

https://developer.apple.com/documentation/uikit/uicolor/ui_element_colors?language=objc

https://developer.apple.com/documentation/uikit/uicolor/standard_colors?language=objc

Thanks, Greg. “systemRedColor” and “systemGreenColor” did the trick. Besides the Apple docs, there’s also a list of valid colors in the Color Picker dropdown menu.

I’m curious how these relate to the different names used in the Color Group class dropdown menu?

Some of them are different because, in our opinion, Apple’s descriptions don’t really tell you what they are… specifically the colors that change dynamically between light and dark variations. Since they have both a “redColor” and a “systemRedColor” we thought it’d be clearer if they latter ones said “Dynamic” instead.