Can't Set a Full-Width Title View in Storyboard using Size Classes

Originator:SlaunchaMan
Number:rdar://21591087 Date Originated:29-Jun-2015 10:41 AM
Status:Open Resolved:
Product:iOS SDK Product Version:Xcode Version 6.3.2 (6D2105)
Classification:UI/Usability Reproducible:Always
 
Summary:
Interface Builder allows you to drag a custom view onto a UINavigationItem to provide a title view using its titleView property. This works great, but you can’t use Auto Layout to size it, and the controls to change its width only extend to the edges of the 600pt-wide simulated view.

Steps to Reproduce:
1. Create a view controller embedded in a navigation controller in your Interface Builder storyboard.
2. Drag a view onto the middle of the navigation bar of the view controller to set the title view. In my example, it’s a UITextField.
3. Add left and right bar button items to the navigation items.
4. Drag the title view to be as wide as possible.
5. Run the app on a landscape iPad simulator.

Expected Results:
The title view fills the width of the navigation bar, with appropriate margins between it and the bar button items.

Actual Results:
The title view’s width does not increase. On smaller devices, there is no margin between it and the bar button items.

Version:
Xcode Version 6.3.2 (6D2105)

Notes:
Here’s a workaround in the view controller:

// We can look at the frame in the 600✕600 view in the storyboard to derive the
// margin between the text field and the bar button items. In this case the full
// width is 600 points and the text field is 485 points wide.
let kTextFieldWidthOffset: CGFloat = 600 - 485

class ViewController: UIViewController {

    @IBOutlet weak var titleTextField: UITextField?
 
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        
        if let textField = titleTextField {
            let width = view.bounds.width - kTextFieldWidthOffset
            
            var frame = textField.frame
            
            if frame.width != width {
                frame.size.width = width
                textField.frame = frame
            }
        }
    }
    
}

Sample project attached.

Configuration:
iOS Simulator Version 8.3 (SimulatorApp-565.9 CoreSimulator-117.15)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!