app designer switch problem
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello community!
I want to use a switch to control the UI theme, like light mode and dark mode. But I can only switch it once, the second time I click, no response. Here are the codes:
% Value changed function: Switch2
function Switch2ValueChanged(app, event)
value = app.Switch2.Value;
if value
app.UIFigure.Color = [0.5, 0.5, 0.5];
else
app.UIFigure.Color = [1, 1, 1];
end
end
related photos, before I click:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1653156/image.png)
after I click:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1653161/image.png)
However, it can only work once. Can you help me, please?
0 Kommentare
Akzeptierte Antwort
Kojiro Saito
am 27 Mär. 2024
Items property of app.Switch2 is 'On' and 'Off' in this app, so you need to change the if condition to value == "On".
function Switch2ValueChanged(app, event)
value = app.Switch2.Value;
if value == "On"
app.UIFigure.Color = [0.5, 0.5, 0.5];
else
app.UIFigure.Color = [1, 1, 1];
end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!