I found another behavior of the systemLayoutSizeFittingSize: method, after which I expected.
Here is a code snippet for a fast playground that demonstrates behavior, but the same thing in Objective-C:
import UIKit import Foundation var label = UILabel() label.text = "This is a Test Label Text" label.numberOfLines = 0 label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) label.preferredMaxLayoutWidth = 40 let layoutSize = label.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) let intrinsicSize = label.intrinsicContentSize()
I would expect layoutSize and intrinsicSize match.
But in this case, layoutSize is (w 173, h 20) and intrinsicSize is (w 40, h 104)
I would expect both to be intrinsicSize , but it seems that systemLayoutSizeFittingSize: ignores preferredMaxLayoutWidth
Can anyone explain this to me?
Edit: Also
label.setNeedsLayout() label.layoutIfNeeded() let layoutSize = label.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) let intrinsicSize = label.intrinsicContentSize()
does not change the results
source share