フィルターのクリア

app designer switch problem

8 ビュー (過去 30 日間)
Dick
Dick 2024 年 3 月 27 日
コメント済み: Dick 2024 年 3 月 27 日
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:
after I click:
However, it can only work once. Can you help me, please?

採用された回答

Kojiro Saito
Kojiro Saito 2024 年 3 月 27 日
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
  1 件のコメント
Dick
Dick 2024 年 3 月 27 日
Fantastic! Problem solved.
Best Wishes.@Kojiro Saito

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by