3

I want to be able to scale the font size on a storyboard per screen size without writing code to do this, is this possible.

I already tried to set up constraints to adjust the label and set the font scaling factor but what happens then it depending on how long the text is I end up getting a screen that has different font sizes rather than all of the font for that screen being the same size?

Michael
  • 1,769
  • 2
  • 12
  • 21

2 Answers2

3

Xcode provides auto shrinks facility, Which adjust based on screen size Goto Attribute inspector-> Autoshrinks -> Minimum font scale set it to 0.5 or your desired value.

enter image description here

Programmatically

label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
Jack
  • 13,571
  • 6
  • 76
  • 98
  • Hi, already tried that but in my original question I said he depends on how much text is in the label then it might not compress the text so you can end up with a screen that had lots of different font sizes – Michael Aug 02 '17 at 11:46
  • @Michael please elaborate more hence i can answer – Jack Aug 02 '17 at 12:32
  • I want to scale the font on an iPhone SE screen. I have a Table View that has cells. cell contains a label and the length of text in that label varies per cell. if I set the min font scale or size it works ok for text that is right at the end of the label but for the labels that contain text that only contains half then the font size stays the same, so every cell then has inconsistent font depending on how much text is in the label. Ideally I would like it to work out the longest label then get that scaled font size and then scale all of the labels to that same font size so they look the same. – Michael Aug 02 '17 at 14:03
  • @Michael Have you tried adding `UILabel` with constraints top, bottom, leading & trailing with `tableView.estimatedRowHeight = 85.0 tableView.rowHeight = UITableViewAutomaticDimension` ? – Jack Aug 03 '17 at 12:00
  • Yeah but I don't want the size of the cell to expand with the label I just want the font size to reduce as there is other content on the cell and the label I want to display is 1 line long only – Michael Aug 03 '17 at 20:48
0

You can add variations inside the property inspector based on the different devices:

Property Inspector: Label

Note, however, that this will not distinguish between all devices...

Community
  • 1
  • 1
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
  • 1
    Hi yeah but the iPhone in portrait are always compact width and regular height so it doesn't work – Michael Apr 30 '17 at 15:21
  • True. Depends on what you are exactly trying to achieve. – LinusGeffarth Apr 30 '17 at 15:21
  • 2
    Font size that is different on all 3 portrait iPhone sizes – Michael Apr 30 '17 at 15:22
  • 1
    @Michael Wouldn't it be better to change the auto-layout constraints in your design and make those labels able to expand on more lines so they would gracefully distribute their text vertically on devices with less screen real estate? – valeCocoa Sep 24 '17 at 15:53
  • 1
    @valeCocoa Yeah that is a good idea, however the problem is that small screen seem to look better with a smaller font size, otherwise the screen can look zoomed in my option? – Michael Sep 25 '17 at 20:24
  • @michael of course it does, but you don't know if the user has decided to increase (or reduce) text size in settings; and if she has reduced vision issues, she might have as well increased it at the huge size allowed by "larger text" in accessibility. Thus basically the user can decide (or has to because of a sight issue) to have the UI looking as if it were zoomed in. Have a look at this if you haven't yet: https://developer.apple.com/videos/play/wwdc2017/245/ – valeCocoa Sep 25 '17 at 20:51