This is happening because the right-most label is expanding to consume all of the remaining space. To achieve the expected outcome, we have to do two things:
Change the VFL to explicitly set each of the label widths to be the same. You can do this by changing the format to H:|[label1][label2(==label1)][label3(==label1)]|
Modify your labels to center align their text using the textAlignment
property.
You can drop the following into a playground to get a better feel for what's going on:
import UIKit
let frame = CGRectMake(0, 0, 500, 500)
let label1 = UILabel()
label1.layer.borderColor = UIColor.redColor().CGColor
label1.layer.borderWidth = 1
label1.text = "Label 1"
label1.textAlignment = .Center
label1.translatesAutoresizingMaskIntoConstraints = false
label1.sizeToFit()
let label2 = UILabel()
label2.layer.borderColor = UIColor.greenColor().CGColor
label2.layer.borderWidth = 1
label2.text = "Label 2"
label2.textAlignment = .Center
label2.translatesAutoresizingMaskIntoConstraints = false
label2.sizeToFit()
let label3 = UILabel()
label3.layer.borderColor = UIColor.blueColor().CGColor
label3.layer.borderWidth = 1
label3.text = "Label 3"
label3.textAlignment = .Center
label3.translatesAutoresizingMaskIntoConstraints = false
label3.sizeToFit()
let view = UIView(frame: frame)
view.backgroundColor = UIColor.grayColor()
view.addSubview(label1)
view.addSubview(label2)
view.addSubview(label3)
let originalFormat = "H:|[label1][label2][label3]|"
let newFormat = "H:|[label1][label2(==label1)][label3(==label1)]|"
let views = ["label1": label1, "label2": label2, "label3": label3]
let constraints = NSLayoutConstraint.constraintsWithVisualFormat(originalFormat, options: [], metrics: nil, views: views)
view.addConstraints(constraints)
view.layoutIfNeeded()
view
Using the originalFormat
you get this:

With my proposed changes you get this:
