UIButton that resizes to fit its titleLabel

Swift 4.x version of Kubba’s answer: Need to Update Line Break as Clip/WordWrap/ in Interface builder to corresponding buttons. class ResizableButton: UIButton { override var intrinsicContentSize: CGSize { let labelSize = titleLabel?.sizeThatFits(CGSize(width: frame.width, height: .greatestFiniteMagnitude)) ?? .zero let desiredButtonSize = CGSize(width: labelSize.width + titleEdgeInsets.left + titleEdgeInsets.right, height: labelSize.height + titleEdgeInsets.top + titleEdgeInsets.bottom) return desiredButtonSize } … Read more

Auto-layout: What creates constraints named UIView-Encapsulated-Layout-Width & Height?

Based on a ton of observation I believe (but cannot know for certain) that the constraints named UIView-Encapsulated-Layout-Width and UIView-Encapsulated-Layout-Height are created by UICollectionView and friends, and exist to enforce the size returned by the sizeForItemAtIndexPath delegate method. I guess it’s there to ensure that the UICollectionViewCell set up by cellForItemAtIndexPath ends up the size … Read more

Disable autolayout constraint error messages in debug console output in Xcode

Did some decompiling and there’s actually a way: for Swift 5 UserDefaults.standard.set(false, forKey: “_UIConstraintBasedLayoutLogUnsatisfiable”) Objective-C [[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@”_UIConstraintBasedLayoutLogUnsatisfiable”]; Now you’ll only get notified that “_UIConstraintBasedLayoutLogUnsatisfiable is OFF”. Obligatory reminder for anyone reading this: this should be last resort, for tips on debugging and fixing constraint issues see WWDC’s “Mysteries of Auto Layout” sessions: part … Read more