8

iPhone 6S Plus's screen is very big compared to other screen sizes. I can't seem to find a good way to handle the font size of a label without adjusting the size programmatically.

How can I adjust the font size of a label so that it looks smaller on an iPhone 5 and bigger on an iPhone 6 Plus?

Cesare
  • 9,139
  • 16
  • 78
  • 130
  • What does "control its size class" mean? Xcode lets you create constraints that are conditional based on size class. What problem remains? Also, what does "the labels appear messed up" mean? _My_ labels aren't "messed up" on an iPhone 6 Plus, so shouldn't you be asking yourself why yours are? – matt Jan 07 '15 at 20:28
  • Thank you for replying my question Matt. The problem is that the size classes you use to control the other iPhone's sizes aren't accurate enough. For example, if I place a label at the top of the UIViewController the same label looks good on a 4 inches iPhone but it doesn't on a iPhone Plus and it needs some resizing. The bad thing is I can't resize it because iPhone 6 Plus hasn't got its own size class therefore I must keep other iPhone's constraints. – Cesare Jan 07 '15 at 20:32
  • 2
    Learn how auto layout works. – Fogmeister Jan 07 '15 at 20:33
  • Are you telling me there’s a way to target the iPhone 6 Plus in portrait? If so, what's that about? Thanks. – Cesare Jan 07 '15 at 20:34
  • "if I place a label at the top of the UIViewController the same label looks good on a 4 inches iPhone but it doesn't on a iPhone Plus and it needs some resizing. The bad thing is I can't resize it" The size of a label is based on its contents. If its contents don't change, why would it need resizing? Is the problem that you want to resize the _font_ of the label? Then use dynamic text, letting the user resize it, or else change it in code and let the label resize itself in response. – matt Jan 07 '15 at 20:37
  • That definitely makes sense, thank you Matt! So I guess my problem is more concerned about the font size, rather than the content inside the label. Is there any way to control the iPhone 6 Plus's font size? I heard someone talking about Auto Shrink but I'm not sure. Thanks! – Cesare Jan 07 '15 at 20:40
  • As I said (badly), if you use Dynamic Type then you can just let the user's preferences deal smoothly with the text size. But you cannot escape having to set the size in code. You can tell if you're on an iPhone 6 plus because it has a triple-resolution screen, which you can easily detect in code. – matt Jan 08 '15 at 00:50
  • Thank you again Matt. Please post that comment as an answer and I'd be glad to accept it. Anyway, may I please know how to use Dynamic Type? – Cesare Jan 08 '15 at 11:59
  • what about _size classes_? – holex Sep 22 '15 at 15:56
  • @CeceXX you have bumped this question again by editing it. But you have already answered and accepted your own answer. No one else is going to add to this. If you'd like a new answer then I'd suggest deleting your answer and adding the code that you have tried into the question. – Fogmeister Nov 19 '15 at 13:57
  • @Fogmeister you're right. I just wanted to make it look like pristine, but you're right when you say there's no point in bumping a question already answered. – Cesare Nov 19 '15 at 15:59

3 Answers3

6

Don't change font sizes for the iPhone 6 or iPhone 6+.

People buy these phones to see more content. The 6+ displays things slightly bigger than the other phones anyway (yes, it has bigger pixels, not just more pixels), and if a user wants an even bigger display they can switch the whole phone to zoom mode (both 6+ and 6; this turns a 6+ into a large 6, and a 6 into a large 5).

Just use autolayout to position things relative to the screen size.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • 2
    _"People buy these phones to see more content."_ such statement is not true omnipotently. – holex May 27 '16 at 13:54
1

You can't target iPhone 6 Plus using AutoLayout because it's not meant for hardcoding sizes. You either need to use code and do something like this:

if UIScreen.mainScreen().bounds.size.width == 375 {
    // iPhone 6
    label.font = label.font.fontWithSize(20)
}

or just create a invisible view and set top and bottom constraints to it.

Community
  • 1
  • 1
Cesare
  • 9,139
  • 16
  • 78
  • 130
  • This doesn't work in landscape mode. And it breaks if the user chose a large font themselves. And of course it will break if the iPhone 7 is 380 pixels wide. – gnasher729 Dec 03 '15 at 15:17
1

I think it is better to use adaptive fonts (here is an example, section Adaptive Fonts)

Oleshko
  • 2,923
  • 4
  • 17
  • 25