简体   繁体   中英

Shrink button font size in Stackview (Swift)

I have two stackViews with buttons in each one. At my chosen font size, they extend off the screen on smaller phones.

I want to reduce the font size of ALL buttons in BOTH stackViews and want all buttons to have the same font size. Is there a simple way to dynamically adjust the font size of all buttons in both stackViews so that they all fit properly and have the same font size?

I could hard-wire it by counting the characters in each title of the largest stack view then calculate the percentage of the view width and scale the font size for all of them but I am wondering if there is anything built-in.

("fillEqually" won't work because the button titles have different lengths so the buttons are different widths.)

Here is an example:

在此处输入图像描述

在此处输入图像描述

sorry,I don't quite understand what you mean. In my opinion, the width of button is calculated automatically. By default, we don't need to specify size and font, and swiftui can display normally. If you need to set font size, you can continue to specify font after button. 在此处输入图像描述

set font like this: 在此处输入图像描述

The only way I can think of is to display the frame on a small screen device by specifying the minimum and maximum width and height values of the frame, as well as the number of rows, which may be helpful在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM