Scale Text Label by Screen Size

How do I change the font size according to screen size

Use minimum font scale instead of minimum font size. Minimum font size was deprecated in IOS 6. In the image although mine says fixed here you can change that and then set the scale factor.

To vary by size of the screen you can do some of that with interface builder. See image. This is using size classes.
AddFontSize

Other ways would be to increase the font size to a large number and let it scale, set it in code by device type, or set a constraint on the label to make it grow and shrink between different sizes and have the scaling set right.

Adjust text size based on user's screen size in Tkinter

Solution:

# determining OS of user
# ratio is to compensate for text size differential between Windows and macOS
# every text attribute's font size should be preceded by int(RATIO * {font size})

if sys.platform == "win32":
RATIO = 1
elif sys.platform == "darwin":
RATIO = 1.375

1920 is my base case since that's what I'm developing with but is what you should adjust, if not my RATIO of 1.375 since it could be slightly off.

SCREEN_WIDTH, SCREEN_HEIGHT = root.winfo_screenwidth(), root.winfo_screenheight()

RATIO *= SCREEN_WIDTH / 1920

How do I make text labels scale the font size with different Apple product screens?

You can actually do it in your Storyboard.

1, open File Inspector tab(First tab) on your storyboard, set both Use auto layout and Use size classes check.

2, Then you can go to your label attribute(Forth tab), you will notice that there is a "+" beside, click it to add.

3, Choose the screen size u want like, can refer "Adaptivity and Layout" and then select your font size.

Answer refer to THIS LINK, you can also take a look

how to make the label proportional to the screen size?

You can do it by setting both proportional width of the label and allow it to scale down the point size.

Set the label width to proportional width like this. It is just a regular same width constraint that you edit.

Sample Image

Then allow your label to scale down the point size like this. This is a property of your label.

Sample Image

How to scale the button text based on screen design swift?

Are you sure it's not working?

Edit - After comments...

UIKit elements such as UILabel / UIButton / etc to not have a built-in "auto-adjust font height" property.

I don't work for Apple, so just guessing that is (at least in part) due to the fact that, in general...

Based on screen height, the UI is designed to either:

  • provide more or less information, e.g. more rows in a table, or
  • adjust vertical spacing between elements

That doesn't mean you can't or shouldn't adjust your font sizes... it just means you have to do it manually.

Couple options:

  • set the font-size at run-time, as suggested by Duncan
  • use a UIAppearance proxy to set the font-size, again at run-time

in either case, you could use a height-to-fontSize table or a "percentage" calculation.

Another option would be a custom class that sets the font-size based on the constrained button height.

Here's a simple example (note: for demonstration purposes only):

class AutoFontSizeButton: UIButton {

override func layoutSubviews() {

super.layoutSubviews()

guard let fnt = titleLabel?.font else { return }

// default system type button has 6-pts top / bottom inset
// and font size is 15/18ths of that height
let h = ((bounds.height - 12.0) * (15.0 / 18.0)).rounded()
let fs = fnt.pointSize

if h != fs {
titleLabel?.font = UIFont(descriptor: fnt.fontDescriptor, size: h)
}

}

}

Result - the top three (yellow) buttons are 30, 40 and 50-points in height, with the default font-size of 15. The bottom three (green) buttons are again 30, 40 and 50-points in height, but the font-size is automatically set at run-time:

Sample Image

How to scale text to fit parent view with SwiftUI?

One can use GeometryReader in order to make it also work in landscape mode.

It first checks if the width or the height is smaller and then adjusts the font size according to the smaller of these.

GeometryReader{g in
ZStack {
Circle().strokeBorder(Color.red, lineWidth: 30)
Text("Text")
.font(.system(size: g.size.height > g.size.width ? g.size.width * 0.4: g.size.height * 0.4))
}
}

Sample Image
Sample Image

How to reduce and increase the font size based on screen size in iOS

To achieve this:

  1. click on the label and go to the attributes pane
  2. change the "lines" to 0
  3. In autoshrink click on minimum font size and set it to about half the size of your main font or a much smaller font


Related Topics



Leave a reply



Submit