How can I use a xib with auto layout in iCarousel? - ios

I have an iCarousel set up to reuse a certain xib. This xib is using AutoLayout (as I am in the rest of my project). Apparently iCarousel does not use AutoLayout, and it does not work correctly with it. The view's constraints appear to be calculated for another frame, and then the view seems to resize...
I have an example project showing my setup here
Here are some images of my troubles:
The first view is correct:
The second and all the others screw up in another way:

Related

Cannot change custom UICollectionViewCell in Storyboard

I have a UICollectionView with custom UICollectionViewCells. I used Interface Builder (via XCode 8) to size the collection view and cells when first making it.
Now, I'm trying to adjust the size of the cells and I'm unable to do so in Interface Builder (using XCode 9). I cannot adjust the width or height of the cells on either the collection view itself or on the custom cell. The up/down arrows don't do anything and neither does typing in a value. It just stays set at 145.
I saw some answers about not being able to do this with a UICollectionViewController via Interface Builder, only a UICollectionView, but it is a collection view and not UICollectionViewController.
I'm sure there's some new setting/config in XCode 9 that I'm missing, but I can't figure out why I can't adjust the custom value.
I ran into the same problem.
Turned out that the item size was defined by the contained flow layout. So editing the item size in the flow layout, and the parent collection view had its item size changed accordingly.
I tried Jonny's answer, but I use a custom FlowLayout and couldn't edit it's cell size either. I had to manually edit the size of the collection view, the cell and the layout in the storyboard source code (right-click on the storyboard in project view and select "open as / source code").
Now the size is correct but still not editable from the UI ¯_(ツ)_/¯
Same problem, width would not change. But I changed the height to something different and it then let me edit the width.
Xcode 12.3. I had the same issue and what fixed it for me was changing the collection view scroll direction from vertical to horizontal to make the change, then obviously reverting back to vertical (my intended direction) once I was done editing the values.

Handling multiple Xib or fixing collapse and expand button on multiple Xib file

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?

autolayout constraints in nib not honored for UITableViewHeaderFooterView

I have a UITableView with several columns of data. The reusable cells are loaded from an xib file which has the appropriate labels and autolayout constraints. Everything works perfectly; the table columns are laid out correctly on different devices and when the devices are rotated.
The problem I am having is trying to create a table footer to show the totals of the columns in the table.
I created an xib file with the same autolayout constraints as the cell xib file and am loading it in tableView.viewForFooterInSection the same way I did for the cells. As required, I am using a subclass of UITableViewHeaderFooterView instead of UITableViewCell.
The awakeFromNib method in the UITableViewHeaderFooterView subclass sets the background color, so I can see that it is the correct size on all devices/orientation, but the labels from the footer xib file are not getting laid out to match the table cells.
The autolayout constraints from the footer xib file are not being honored. When I set a different background color in the footer xib file, the table footer shows this background color for the length of the xib's view.
I'm new to all of this technology and would greatly appreciate help in resolving this incredibly frustrating issue.
Is there a way to use autolayout for UITableViewHeaderFooterViews loaded from nibs?
You should call setNeedsUpdateConstraints() to update your view.
From apple documentation
Controls whether the view’s constraints need updating.
When a property of your custom view changes in a way that would impact constraints, you can call this method to indicate that the
constraints need to be updated at some point in the future. The system
will then call updateConstraints as part of its normal layout pass.
Updating constraints all at once just before they are needed ensures
that you don’t needlessly recalculate constraints when multiple
changes are made to your view in between layout passes.
Also, you can update view throw layoutSubviews()
Lays out subviews. The default implementation of this method does
nothing on iOS 5.1 and earlier. Otherwise, the default implementation
uses any constraints you have set to determine the size and position
of any subviews. Subclasses can override this method as needed to
perform more precise layout of their subviews. You should override
this method only if the autoresizing and constraint-based behaviors of
the subviews do not offer the behavior you want. You can use your
implementation to set the frame rectangles of your subviews directly.
You should not call this method directly. If you want to force a
layout update, call the setNeedsLayout method instead to do so prior
to the next drawing update. If you want to update the layout of your
views immediately, call the layoutIfNeeded method.

Resize UITable Header View Auto Layout

I am building a simple iOS application using Swift.
One of my views, displays a list of comments (cells in a PFQueryTableViewController...I am using Parse.com for my database).
My cells resize happily in order to fit the possible multiple-lines of the comments. This is MAGIC! (if you ask me)
What I am having trouble doing, is making the UIView which is at the top of the TableView resize based on multiple lines worth of content for the Label in that top view (see below).
Instead of doing multiline and resizing the view (I have set up constraints and set lines of text to 0), the label only shows one line, truncating it at the edge of the screen with "..."
Does anyone have any suggestions or solution for how to cause my top UIView to resize based on the content of the UILabel?
I was also thinking this could maybe better be done using a Container View at the top of the TableViewController?
There is a delegate method in UITableViewDelegate that lets you return the height of the head view (heightForHeaderInSection). You have to implement it making sure you return the proper height.
If you have a nib with constraints already, you can load the nib in a #property, and use the method systemLayoutSizeFittingSize that should give you enough height.
For more details checkout this post I wrote a while ago: Customize the UITableview with different height of cells like Facebook feeds in iOS

UISegmentedControl with UITableView

I have the following views set up in IB for my project: UITabBarView->UINavigationView->MyCustomViewController.
I added a UISegmentedControl and a UITableView to the CustomView via IB by just dragging them onto the screen. I would like my app to look very similar to the AppStore app. Everything looks fine in IB; however, once it populates the UITableView with data, it covers the whole underlying view with a single cell (the segmented control is covered).
I didn't want to have to do everything in code so I've tried to stick with IB since this seems simple enough. Does anyone know why my UITableView is taking up the whole frame?
I figured out what was going on. I was incorrectly re-sizing the table view cell when binding the data. I ended up using the new prototype cells in the storyboard instead of trying to create a separate nib.

Resources