@MatthiasBauch's comment helped me track down the whole solution, as detailed below:
NOTE: I'm using Autolayout, so anywhere I use the Storyboard you'll have to substitute it with the programmatic equivalent.
1) First, drag a "Segmented Control" out on the the storyboard.
2) Create an Outlet for the Control you just added.
3) Also, ctrl+click on the Control, and drag to itself. Then click on "width" to add a width constraint.
4) Now, open the Document Outline (Editor > "Reveal Document Outline")
5) Open the "View" that the Segmented Control is in, then open the dropdown for the Segmented Control (mine was named "First, Second" by default). Then open "Constraints".
6) Ctrl+click on the "Width" constraint you just made and drag over to your view controller to create an Outlet for it. This will allow you to adjust the width programmatically.
Using the article mentioned below, you can update the constraint as follows (using animation...bonus!)
Go to the method you want to use to update the width and do the following:
let desiredWidthChange = 30.0
self.widthConstraint.constant =
self.mySegmentedControl.constant + desiredWidthChange
self.mySegmentedControl.setNeedsUpdateConstraints()
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.mySegmentedControl.layoutIfNeeded() // Captures all of the frame changes.
println("Width updated successfully")
})
Reference:
Are NSLayoutConstraints animatable?