Main Content

uiswitch

슬라이더 스위치, 로커 스위치 또는 토글 스위치 컴포넌트 만들기

설명

sw = uiswitch는 새 Figure 창에 슬라이더 스위치를 만들고 Switch 객체를 반환합니다. MATLAB®uifigure 함수를 호출하여 Figure를 만듭니다.

sw = uiswitch(style)은 지정된 스타일의 스위치를 만듭니다.

예제

sw = uiswitch(parent)는 지정된 부모 컨테이너에 스위치를 만듭니다. 부모 컨테이너는 uifigure 함수를 사용하여 만든 Figure이거나 그 자식 컨테이너 중 하나여야 합니다.

예제

sw = uiswitch(parent,style)은 지정된 부모 컨테이너에 지정된 스타일의 스위치를 만듭니다.

예제

sw = uiswitch(___,Name,Value)는 하나 이상의 Name,Value 쌍의 인수를 사용하여 객체 속성을 지정합니다. 위에 열거된 구문에 나와 있는 입력 인수를 조합하여 이 옵션과 함께 사용하십시오.

예제

모두 축소

fig = uifigure;
sliderswitch = uiswitch(fig);

Slider switch in a UI figure window, with a value of Off on the left and On on the right. The value of the switch is Off.

fig = uifigure;
toggleswitch = uiswitch(fig,'toggle');

Toggle switch in a UI figure window, with a value of On at the top and Off at the bottom. The value of the switch is off.

패널에 로커 스위치를 만듭니다.

fig = uifigure;
pnl = uipanel(fig);
rockerswitch = uiswitch(pnl,'rocker');

Rocker switch in a panel in a UI figure window, with a value of On at the top and Off at the bottom. The value of the switch is off.

로커 스위치를 만듭니다.

fig = uifigure;
rockerswitch = uiswitch(fig,'rocker');

스위치 텍스트를 만듭니다.

rockerswitch.Items = {'Stop','Start'};

현재 스위치 값을 결정합니다.

val = rockerswitch.Value
val =

    'Stop'

Rocker switch in a UI figure window, with a value of Start at the top and Stop at the bottom. The value of the switch is Stop.

다음 코드를 MATLAB 경로에 lampswitch.m으로 저장합니다. 이 코드는 램프와 로커 스위치가 포함된 앱을 만듭니다. 사용자가 스위치를 돌리면 ValueChangedFcn 콜백이 램프 색을 변경합니다.

function lampswitch
fig = uifigure('Position',[100 100 370 280]);


lmp = uilamp(fig,...
    'Position',[165 75 20 20],...
    'Color','green');


sw = uiswitch(fig,'toggle',...
    'Items',{'Go','Stop'},...    
    'Position',[165 160 20 45],...
    'ValueChangedFcn',@switchMoved); 

% ValueChangedFcn callback
function switchMoved(src,event)  
    switch src.Value
        case 'Go'
            lmp.Color = 'green';
        case 'Stop'
            lmp.Color = 'red';
        end
    end
end

lampswitch를 실행하고 스위치를 클릭하여 색 변경을 확인합니다.

Toggle switch and lamp in a UI figure window. The switch has values of Stop and Go, and is flipped to Go. The lamp is green.

입력 인수

모두 축소

스위치의 스타일로, 다음 표의 값으로 지정됩니다.

스타일모양
'slider'Slider switch, with a value of Off on the left and On on the right. The value of the switch is Off.
'rocker'Rocker switch, with a value of On at the top and Off at the bottom. The value of the switch is Off.
'toggle'Toggle switch, with a value of On at the top and Off at the bottom. The value of the switch is Off.

부모 컨테이너로, uifigure 함수를 사용하여 만든 Figure 객체나 그 자식 컨테이너인 Tab, Panel, ButtonGroup, GridLayout 중 하나로 지정됩니다. 부모 컨테이너를 지정하지 않을 경우 MATLAB은 uifigure 함수를 호출하여 부모 컨테이너 역할을 하는 새 Figure 객체를 만듭니다.

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

R2021a 이전 릴리스에서는 쉼표를 사용하여 각 이름과 값을 구분하고 Name을 따옴표로 묶으십시오.

예: 'Text',{'0','1'}은 두 개의 스위치 상태가 "0"과 "1"임을 지정합니다

각 유형의 스위치는 서로 다른 속성 모음을 지원합니다. 전체 속성 목록과 각 유형에 대한 설명을 보려면 관련 속성 페이지를 참조하십시오.

버전 내역

R2016a에 개발됨

모두 확장