Windows/Mac font size differences have become unworkable.

6 次查看(过去 30 天)
Please can someone tell me what I'm doing wrong to have a GUI be usable on both Windows and Mac? I have a client application that I have to re-build when a new version of the server is released. This is usually no real work.
There have always been slight differences between the display of fonts and spacing of text labels on my GUI between Windows and Mac, but not enough to cause real problems.
However, now I find that if labels are acceptable on Windows they are really really tiny on Mac - unreadable really. So I increase the font size and suddenly the text is so huge in windows that it doesn't fit in the label box.
I build the GUI in guide, all GUI components are set to 'Character' for units, and all fonts are specified by 'points'. None of the windows are resizable. I am using R2017b.
I have tried many fonts, including 'default', but cannot find a happy medium that works for my application. This has become a real blocker for getting new version of the client to users. Can anyone suggest a solution??
Many thanks.

回答(1 个)

Brian
Brian 2020-9-25
One workaround I've had some success with is scaling all of the text of the figure using a recursive function called at the end of the xxx_OpeningFcn.
In the mfile of your GUI, define the following function:
function parent = fixFontSize(parent,fontSizeFactor)
% Check if parent has 'FontSize' property. If so, scale by fontSizeFactor.
if isprop(parent,'FontSize')
parent.FontSize = parent.FontSize*fontSizeFactor;
end
% Recursively act on each child of parent.
for ii = 1:length(parent.Children)
if ~isempty(parent.Children(ii))
parent.Children(ii) = fixFontSize(parent.Children(ii),fontSizeFactor);
end
end
At the end of your xxx_OpeningFcn, place the following code:
if ispc
handles.figure = fixFontSize(handles.figure,0.8);
end
where handles.figure is the field in which all the properties of the figure is located. It might be named differently depending on how you defined your figure in GUIDE. You can adjust the fontSizeFactor to be whatever scales your PC UI best. If certain types of uicontrols are scaled inappropriately, it wouldn't be too difficult to assign a different size factor for certain types.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by