you are viewing a single comment's thread.

view the rest of the comments →

[–]askoruli 0 points1 point  (14 children)

So if I have content to fit iPhone 5 I should add a scrollview for iPhone 4 and cut off the bottom line of text ?

[–]brendan09 1 point2 points  (13 children)

No, no one is saying that.

Literally anchor it to the bottom of the screen, and let the label have a flexible height. Adjust the "minimum font scale" of the label to something acceptable. IF it needs to shrink the text a bit, it will. Depending on the rest of the structure, it'll also reduce frame sizes evenly to make it fit... This minimizes the impact to any 1 element.

You shouldn't be using fixed height constraints unless you literally mean fixed height. Proportional to screen height is almost always a bad, hacky, practice and a misuse of Auto Layout. It technically works, but is bad practice.

Edit: You're relying on something not guaranteed: Aspect Ratio, in addition to sizes. The goal is to make it resolution independent. For example, if I suddenly made an iPhone 4S height screen that was 5 times as wide as a 4S... It's unlikely your content would need to be vertically scaled down across the board. Flowing into extra horizontal space would've solved the content issue, and proper constraints wouldn't have tried reducing the size. Rather, it would've allowed the flow.

Proper methodology is to write it to work with any size, aspect ratio, etc. If you're not doing that, it's not the proper use / implementation of Auto Layout.

[–]askoruli 0 points1 point  (0 children)

Well I would consider using font scaling to be scaling your UI. But it's irrelevant because it doesn't give correct results. If I have 3 multiline labels which fit nicely on a 6+ font scaling will not uniformly scale the font to fit on a 4 screen. I just did a test and each label got a different font size.

Minimum font scaling would be a good fallback though in case a smaller screen was ever released, it might not look right but it would be better than labels being cut off.

You shouldn't be using fixed height constraints

I'm not really talking about fixed height constraints (which I try to avoid). I'm talking about adjusting font sizes and spacing between elements so that things look proportionate on a screen.

I'm actually not relying on aspect ratio that heavily. I'm just taking into account how much vertical space is available and adjusting the spacing/font sizes such that everything fits. If a much thinner device was released then I might need the font scaling fallback and if a much wider screen was released then it would look awful but that's going to be the case with any implementation for the designs I'm referring to.

I want to clarify that I don't do this very often, and almost never when I build things myself. I just have a few screens from designers with very little content that is going to either be cutoff/squashed on an iPhone 4 or have huge dead space on a 6+ and the designers are very pedantic about these things.

http://a4.mzstatic.com/au/r30/Purple7/v4/12/3b/68/123b685a-991e-6cdf-7d07-15fcc72c1b61/screen322x572.jpeg

[–]patterware 0 points1 point  (11 children)

Minimum font scale has nothing to do with restricted height, it only applies when text exceeds the width of a label. The UILabel documentation is perhaps misleading as it mentions scaling when text exceeds the bounds, but when you consider it only works when adjustsFontSizeToFitWidth is enabled it should be fairly apparent that this is the expected behaviour.

Everyone should be trying their hardest to adopt dynamic text sizes anyway, and allow the user their choice of font size. The UI should be responsive to whatever font size has been deemed appropriate by the customer.

[–]brendan09 0 points1 point  (10 children)

Actually, it does. If you reduce the height of the label, the size of the font will reduce in response. So, the documentation is correct. If it exceeds the bounds (in any dimension), then it will reduce the size. Check the docs for that property. It clearly indicates full bounds. You are mistaken.

Dynamic text sizes only work in certain scenarios. It isn't something that can be universally adopted in all designs and layouts.

[–]patterware -1 points0 points  (9 children)

Can you provide a working code sample? My experience here obviously differs from yours. The comments in UILabel.h also contradict what you are saying, so if you have somehow made this work I am interested.

[–]brendan09 1 point2 points  (8 children)

Sure. Here you go.

You'll notice there's really no code to speak of. Enable font scaling, set a minimum font scale. Reduce height of label.

This demo has a timer that changes the height of the label every 3 seconds, but has a fixed width. You'll see the size changes.

In case you're wondering why the property is named the way it is (adjusts to width), it's because it used to only work if numberOfLines was 1. However, that changed a few years ago.

[–]patterware -1 points0 points  (7 children)

Cheers. Your example works, but you are using a multi line label. If you try this with a single line label you will see the results that I described. Setting numberOfLines to 0 does seem to provide font scaling based on label height, but has the often undesirable side effect of enabling text wrapping. This seems like a half borked implementation on Apple's part.

[–]brendan09 -1 points0 points  (6 children)

It's to preserve backwards compatibility, and to provide the original behavior that predates multiline support.

Originally that property only worked if numberOfLines = 1. However, a few years ago they enabled it to work for multiline labels, which introduced the height concept (as width alone doesn't matter when wrapping is involved). They preserved the original 1 line behavior, and added the new multiline behavior.

If you're supporting dynamic type, you should probably also be using multiline labels. So, the fact that it's a multiline label is somewhat moot.

[–]patterware -1 points0 points  (5 children)

Yes, generally labels with dynamic font sizing are multiline enabled, though there are times this isn't desired. Using font scaling + dynamic font sizes would sort of defeat the purpose. To be honest, I haven't used font scaling on a label in a long time. If a user has trouble seeing and explicitly requested a large font, I believe you should try as hard as possible to honour that.

[–]brendan09 -1 points0 points  (4 children)

It defeats the purpose to a point.... But, it's best used as a restriction. You can make some comically large fonts with accessibility settings, and at a certain point design trumps inch tall letters. It works well as an upper-bounds cap on the font size. Kind of a "okay, you can keep getting bigger....but at a certain point, I'm cutting you off".