How to debug a layout using Multiline UILabel / autolayout in extending notification content

How to debug the following problem? Is there any way around this problem?

There seems to be a bug in iOS 10.2 and below when creating multi-line UILabel.

I have a fairly simple subclass of UIView, which I use both in the extension of the contents of the application and in the notification, which looks like this:

UIView custom subclass in interface builder

In the main application, everything was laid out just fine:

the correct layout, if shown in the main application

If the extension displays notification content on iOS 10.2 and below, the layout is broken. But only when the text is long enough to break into several lines. It seems like iOS cannot calculate the correct height of the whole view:

broken layout in iOS 10.2

However, this problem seems to be fixed on iOS 10.3 and later:

correct layout in iOS 10.3

+5
source share
1 answer

I started experimenting with subviews, in particular by setting fixed height limits.

It turns out that it was not the label (s) that caused the problem with calculating the total height, but the limitation of the aspect ratio (width: height) in the upper view.

Programmatically calculating the height based on the width of the view and setting the height limit for the affected view helped solve the problem:

public override func updateConstraints() { super.updateConstraints() if #available(iOS 10.2, *) { imageContainerHeightConstraint.isActive = false } else { // FIX: multiline label / aspect ratio / autolayout bug in iOS < 10.2 let ratio: CGFloat = imageContainerAspectRatioConstraint.multiplier imageContainerHeightConstraint.constant = round(bounds.width/ratio) imageContainerHeightConstraint.isActive = true } } 
0
source

Source: https://habr.com/ru/post/1269902/


All Articles