Switch button app-designer

19 views (last 30 days)
dario cecchetti
dario cecchetti on 3 Jan 2019
Answered: Sachin Meena on 8 Jan 2019
Hi everyone, my goal is to get the SWITCH button off, by pressing the BUTTON button. Is it possible?
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
SwitchLabel matlab.ui.control.Label
Switch matlab.ui.control.Switch
end
methods (Access = private)
% Value changed function: Switch
function SwitchValueChanged(app, event)
end
% Button pushed function: Button
function ButtonPushed(app, event)
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [115 376 100 22];
% Create SwitchLabel
app.SwitchLabel = uilabel(app.UIFigure);
app.SwitchLabel.HorizontalAlignment = 'center';
app.SwitchLabel.Position = [300 346 41 15];
app.SwitchLabel.Text = 'Switch';
% Create Switch
app.Switch = uiswitch(app.UIFigure, 'slider');
app.Switch.ValueChangedFcn = createCallbackFcn(app, @SwitchValueChanged, true);
app.Switch.Position = [298 376 45 20];
end
end
methods (Access = public)
% Construct app
function app = app1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Accepted Answer

Sachin Meena
Sachin Meena on 8 Jan 2019
You should be able to do that by defining appropriate callback functions. For this scenario, you can write a ButtonPressed callback function such that it turns the Switch to 'off' state.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!