I am trying to create a reusable view (xib) and use it in my storyboard with autolayout. The problem is that it does not seem to use the constraints that I have set up on the storyboard for it.
So my realy basic IOS-project contains:
- MyView.swift
- MyView.xib
- Main.storyboard
- ViewController.swift
The MyView class is connected to the xib file in the proper manner:
import UIKit
class MyView: UIView {
@IBOutlet var View: UIView!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NSBundle.mainBundle().loadNibNamed("MyView", owner: self, options: nil)
self.addSubview(self.View);
}
}
In my storyboard i added a UIView (CustomClass=MyView) with 2 simple height/width constraints. When I run the app the view is not sized according to those constraints. It is rendered with the height/width properties in the xib.
Does anyone have a clue on how to make my custom view conform to my constraints that I set up in my storyboard?