table header view height is wrong when using auto layout, IB, and font sizes

Note: A Swift 3+ version can be found here: https://gist.github.com/marcoarment/1105553afba6b4900c10#gistcomment-1933639 The idea is to calculate header’s height with help of systemLayoutSizeFittingSize:targetSize. Returns the size of the view that satisfies the constraints it holds. Determines the best size of the view considering all constraints it holds and those of its subviews. After changing header’s height it … Read more

On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors…?

See this UIKit: Apps for Every Size and Shape before and after reading this. Might also want to see the notes from here as well. Being the Bounty offerer…I’d say the majority of my confusion came from not properly understanding the UILayoutGuide class. That is key, but also very simple. Let me first introduce a … Read more

Can I use autolayout to provide different constraints for landscape and portrait orientations?

Edit: Using the new concept of Size Classes introduced in Xcode 6, you can easily setup different constraints for specific size classes in Interface Builder. Most devices (e.g. all current iPhones) have a Compact vertical size class in landscape mode. This is a much better concept for general layout decisions than determining the device’s orientation. … Read more

iOS ScrollView needs constraint for y position or height

Whenever using ScrollView with auto layout always follow below steps, ScrollView constraints: leadingSpace, topSpace, TrailingSpace, bottomSpace to superView and make sure when you control drag to add constraint, add it by pressing alt so that the constraint would be set without margin. Add UIView inside scroll view as container view and set its constraints: leadingSpace, … Read more

When should translatesAutoresizingMaskIntoConstraints be set to true?

translatesAutoresizingMaskIntoConstraints needs to be set to false when: You Create a UIView-based object in code (Storyboard/NIB will set it for you if the file has autolayout enabled), And you want to use auto layout for this view rather than frame-based layout, And the view will be added to a view hierarchy that is using auto … Read more

Auto layout UIScrollView with subviews with dynamic heights

I use pure structure like the following -view -scrollView -view A -view B -Button Make sure Button(THE LAST view) has a constraint(vertical spacing from its bottom to superview, which is the scrollview), in this case, no matter what changes for your view A and view B would be, scrollView’s height will be changed accordingly. I … Read more

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