What is NSLayoutConstraint “UIView-Encapsulated-Layout-Height” and how should I go about forcing it to recalculate cleanly?

I have a UITableView running under iOS 8 and I’m using automatic cell heights from constraints in a storyboard. One of my cells contains a single UITextView and I need it to contract and expand based on user input – tap to shrink/expand the text. I’m doing this by adding a runtime constraint to the … Read more

Getting a “This application is modifying the autolayout engine from a background thread” error?

Been encountering this error a lot in my OS X using swift: “This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.” I have a my NSWindow and I’m swapping in views to the contentView of … Read more

Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

I opened an existing iOS project with Xcode6 beta6, and Xcode lists the following warning for both Storyboard and Xib files: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 I tried addressing the warning by setting the width as explicit like below: Yet this didn’t resolve the warnings. How … Read more

Emulating aspect-fit behaviour using AutoLayout constraints in Xcode 6

I want to use AutoLayout to size and layout a view in a manner that is reminiscent of UIImageView’s aspect-fit content mode. I have a subview inside a container view in Interface Builder. The subview has some inherent aspect ratio which I wish to respect. The container view’s size is unknown until runtime. If the … Read more

How to use Auto Layout to move other views when a view is hidden?

I have designed my custom Cell in IB, subclassed it and connected my outlets to my custom class. I have three subviews in cell content which are: UIView (cdView) and two labels (titleLabel and emailLabel). Depending on data available for each row, sometimes I want to have UIView and two labels displayed in my cell … Read more

How to add constraints programmatically using Swift

I’m trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically in Swift to a UIView using this code: var new_view:UIView! = UIView(frame: CGRectMake(0, 0, 100, 100)); new_view.backgroundColor = UIColor.redColor(); view.addSubview(new_view); var constX:NSLayoutConstraint = NSLayoutConstraint(item: new_view, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: … Read more

Cocoa Autolayout: content hugging vs content compression resistance priority

I can’t find a clear answer on Apple documentation regarding Cocoa Autolayout about the difference between content hugging and compression resistance. Can somebody explain their usages and difference ? 8 s 8 A quick summary of the concepts: Hugging => content does not want to grow Compression Resistance => content does not want to shrink … Read more