I created a project in Swift. I added view controller file and one XIB using right click on the project - > Add Files to projectname -> Empty (xib) file.
After adding the xib file, i removed the view and added View Controller. Under the View controller , i have added few button. But i am not able set the constraints.But if i add the View object instead of View Controller, i am able to set the constraints. I don't understand why the xib constraints are disabled for View controller. Attached the screen shot
Layout is set to Translates Mask Into Constraints, meaning that IB is gonna generate the constraints for you automatically.
Set it to Automatic and it'll work.
Related
I'd like to create a small UIViewController that contains an UITextField and a UILabel going one after the other.
I've decided to use an instance of UIStackView to lay out the subviews.
However, I have to add a UIStackView as a subview of the parent UIView in XIB.
Is it possible to configure XIB the way that the root view of the controller would be of a certain class, eliminating the need for the extra view?
I've attached the current view hierarchy. I'd like to get rid completely off the topmost View.
Yes you can, you need just to set the stackview as the the root view of your view controller as following:
you can do the following:
1- create new file -> under the user interface choose "Empty"
2- then you will get an empty XIB
3- after that you can add your UIStackView from the UI Component picker
4- put your UITextField and UILabel
5- finally create your .swift file and wire it up with your XIB
I am trying to add FooterView(UIView) by dragging down on UITableview through XIB but can't.
Yes we can add it programetically (tableView.tableFooterView = myView) & also works with dragging view in Storyboard,
But I want right from XIB.
You cannot do this in a Xib. If you think about it, a storyboard is somewhat like a collection of Xib files. Thus, in a storyboard you can add a footer view as a kind of 'xib' embedded in that storyboard. A pure xib cannot contain multiple child xib's, so what you want is not possible unfortunately.
I have a table view on storyboard i.e. FirstStory.Storyboard. And for this tableview I have created a table view cell on xib file where I give size to its width as per my current storyboard width. But when I launch my app it runs fine on the landscape position. But when I rotate it in the portrait mode. Width is unable to show the all item which I placed in tableviewcell.xib. How we mutually combine these two item in storyboard (table view on storyboard while cell on xib). Which follow a single constraints with above condition.
UITableViewCell's contentView property is always the size of the cell. So you have to setup the constraints of your UI components in the xib file with the Cell's contentView properly. The issue you are facing must be because you did not setup these constraints properly.
To see which views or constraints have been placed wrong, use the XCode's 'Debug View Hierarcy' feature.
Launch it from here
Run your app, navigate to your tableView, then press the above button to launch the view debugger. It provides very good insight into your constraints and where the issue may lie
Now the situation is illustrated in this image:
I have an app having multiple Xib files calling in one main Xib and its class. I have added expand and collapse view which works on particular xib expand and collapse subviews as required and reduces/Expands Height too.
This works well for one xib section when all tabs of xib files are collapsed and the second xib won't change its y-coordinates, but I'm having a white space between. I want to fix it.
Note: Every xib contains a class referring to it. The whole app won't use auto-resize.
How can I solve this?
In a xib file, i've got a UiCollectionView. I would like to add a header to this UiCollectionView.
According to this article :
Next, open up MainStoryboard.storyboard and click on the collection view inside of the Scene Inspector on the left (you might need to drill down a couple of levels from the main view first). Open up the Attributes Inspector and check the Section Header box under Accessories:
If you look at the scene inspector on the left, a UICollectionReusableView has automatically been added under the Collection View.
I did it, but when I look at the screne inspector on the left, there is no a UICollectionReusableView.
Any suggestion ?
How I correct the problem:
Be sure your UICollectionView delegate is linked with File's owner in xCode.