uilabel - fit width to text
조회 수: 13 (최근 30일)
이전 댓글 표시
Hi,
I have some uilabel objectss in my appdesigner app which are created programmatically while the app is running.
Now I would like to change the size of the uilabel in a way that it fits the text and does not cut it off. How can I do that?
Googling gave me only some information on how to do that with uicontrol objects via the 'Extent' property. Unfortunately, uilabel objects do not have such a property and uicontrols don't work with appdesigner.
I would also be interested in how to fit the label size when the fontsize changes. Maybe that could be done using the same means.
댓글 수: 0
답변 (2개)
claudio duran
2020년 8월 13일
Hi! I have the same problem!
I use many uilabels in different windows and it is somehow not a good practice to set everything by hand.
It would be good to set the text to the length of the layout and, if the text is too large, instead of cutting it, it becomes automatically a new line. Do you know whether this is possible without the manual intervention?
Thanks in advance!
댓글 수: 0
Harsha Priya Daggubati
2020년 7월 27일
Hi,
Usually labels are supposed to be used for labelling purposes, which doesnot need any editing. So you can set the size manually by accessing the 'Position' property of uilabel, so that all the text fits into the label.
Label = uilabel(app.UIFigure);
Label.Text = 'Result';
size = Label.Position(3:4);
Label.Position(3:4) = [62 22];
Hope this helps!
댓글 수: 3
Walter Roberson
2020년 8월 13일
편집: dpb
2024년 7월 31일
"Usually labels are supposed to be used for labelling purposes, which does not need any editing."
That is unrealistic, badly so.
- font size changes to meet user vision needs
- font size changes related to display resolution
- automatic scaling is different in MATLAB for different operating systems running on the exact same hardware, 72 virtual ppi Mac, 100 virtual ppi Windows, no virtual ppi Linux, and the scaling only kicks in above a certain number of pixels for the display
- high pixel count displays are not necessarily physically large displays, with there being a whole market of 1920 displays with different physical sizes, and 3840 displays can be 27", 31", 36", 51"...
- it is completely unacceptable that the ux designer would have to hand-tweak the exact Position of every label or container object just because one spelling mistake was corrected or one copyright year was updated. Or, for that matter, that the user selected a different file in a display where the ux required that the complete name be used as a group label
- It is unacceptable that the ux designer would have to hand tweak the Position of everything to support translation into a different user natural language
Any serious Ux needs the ability to query how much space an object would take up, so that design tools can automatically adjust component placement according to layout policies created by the ux developer.
... especially since the user should be able to grab the window and resize it, and the output components should reflow according to layout policies.
The ability to query required display size by program is required once you get past the point of a program for internal use by a small number of people with the same hardware, and all of whom have good eyesight.
Markus Leuthold
2023년 7월 25일
@Harsha Priya Daggubati, I take again your example and call
uilabel(Text="Result");
So how would you recommend to set the width of uilabel without some hardcoded values? Are there any plans to improve this?
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!