How to wrap text within buttons of app-designer

Is there a way I can chose to wrap the text in my button to a 2nd row, instead of letting it to overflow outside my button?
Thanks!

 채택된 답변

Adam Danz
Adam Danz 2019년 10월 19일
편집: Adam Danz 2021년 4월 30일

3 개 추천

You can make set multi-lined text in a button from within the startup function startupFcn().
The first line below creates two lines of text within the button.
The second line moves the button down and doubles its vertical size. Set the button width and the position of the top of the button from the DesignView.
% Code that executes after component creation
function startupFcn(app, arg1)
app.Button.Text = ['Really long',newline,'button name']; % or sprintf('Really long\nbutton name')
app.Button.Position([2,4]) = app.Button.Position([2,4]) + [-1,1].*app.Button.Position(4);
% If you'd rather the button size to expand upward rather than downward,
% Replace the 2nd line above with
% app.Button.Position(4) = app.Button.Position(4)*2;
end
Update
As of R2020b multi-line text in buttons can be achieved from Design View (thanks Eric Sargent).

댓글 수: 4

Leon
Leon 2019년 10월 19일
It works! Many thanks.
Adam Danz
Adam Danz 2019년 10월 19일
Glad I could help.
I just added to may answer that you can set the button width and the position of the top of the button from the DesignView; but you may have already figured that out.
As of R2020b components that support multiline text now support WordWrap, including uibutton.
uilabel, uitextarea, uibutton, uitogglebutton, uicheckbox, uiradiobutton
Thanks Eric, I updated my answer to increase visibility.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Eric Sargent
Eric Sargent 2020년 12월 9일

1 개 추천

As of R2020b components that support multiline text now support WordWrap, including uibutton.
uilabel, uitextarea, uibutton, uitogglebutton, uicheckbox, uiradiobutton

카테고리

도움말 센터File Exchange에서 Update figure-Based Apps에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2019년 10월 19일

댓글:

2021년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by