I have a nib that has an init method:
override init() {
super.init();
self.view = NSBundle.mainBundle().loadNibNamed("myNib", owner: self, options: nil).first as? UIView;
self.addSubview(self.view);
}
In a UITableView cell, I'm loading the nib like this:
override func awakeFromNib() {
self.myInnerNib = myNib();
self.nibContainerView?.addSubview(self.myInnerNib!);
}
The nib is freeform, and its constraints are set to fill the parent view's container. However, when I load it on a bigger device, it is clear that the view doesn't fill it's parent.
When nibs are loaded, you receive an array of views, and you generally take the top level view and add it as a subview. Is it possible that there is another view between the container and my nib that is preventing the nib from resizing correctly?
EDIT
I was overriding my init with frame method where i was forcing the subviews in the nib to set their frames instead of letting them be implicitly inferred
override init(frame: CGRect) {
super.init(frame: frame);
self.view = NSBundle.mainBundle().loadNibNamed("DayLineGraphView", owner: self, options: nil).first as? UIView;
self.view.frame = frame; <- problem
self.innerView.frame = frame; <-problem
self.addSubview(self.view);
setupGraph()
}
self.addSubview(self.view). So you are adding itself to itself. Also, where are you setting the constraints? - FironibContainerViewmust own the constraints associated with themyInnerNibwhich will need to be done programmatically. Now if you setup the frames to be equivalent then generally the associated constraints on the super view will also be setup for you. - Firo