Kodeco Forums

Video Tutorial: Intro to Auto Layout Part 8: Visual Format Language

Learn how to use the visual format language to create multiple constraints in a much more compact way.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3201-auto-layout/lessons/9

Hi,

Need some help with VFL and auto layout constraints.This is what i am doing.

messageContainer - UIView (The height of this container is calculated dynamically by the collection view cell)
postImage - UIImage
messageTextView - UITextView
postedByLabel - UILabel

    messageContainer.addSubview(postImage)
    messageContainer.addSubview(messageTextView)
    messageContainer.addSubview(postedByLabel)

    messageContainer.addConstraintsWithFormat("H:|-[v0]-|", views: postImage)
    messageContainer.addConstraintsWithFormat("H:|-[v0]-|", views: messageTextView)
    messageContainer.addConstraintsWithFormat("H:|-12-[v0]-|", views: postedByLabel)
    messageContainer.addConstraintsWithFormat("V:|-[v0]-[v1]-6-[v2]-|", views: postImage,messageTextView, postedByLabel)

When the layout appears the messageTextView is expanding and the image is getting squashed. I tried with stack layout also. Same thing is happening. Can you help out

There are more constraints involved than just the ones you’re creating. There are also the intrinsic size constraints for each of those views. It sounds to me like you need to increase the vertical content compression resistance priority of the image and possibly increase the vertical content hugging priority of the text view.