How can I add column headers on top of my uicollectionview for each column?
I've been trying all sorts of things for days and had horrible luck :(
I'm just using a regular uicollectionview and have 20 or so items in it.
I don't need the header to stay floating or anything sophisticated, just need a single label of text above the first row in each column.
Any ideas?
I'm assuming you're using UICollectionViewFlowLayout. You need to set the headerReferenceSize property to something higher than (0, 0). (Or you can implement collectionView:layout:referenceSizeForHeaderInSection: if the header sizes differ.)
Then just provide your header view in collectionView:viewForSupplementaryElementOfKind:atIndexPath:. Your view should be a UICollectionReusableView. These work similarly to cells in terms of reusability.
What has worked for me is to create a UIScrollView above the UICollectionView.Add UILabels for each column in the UIScrollView and keep the scrolling synchronized via the UIScrollViewDelegate method:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
Both the UIScrollView and UICollectionView will take a UIScrollViewDelegate delegate object.
Related
The designer came back with a layout that displays information differently.
Is it possible to make my UICollectionView function like a UITableView? Where each cell takes up one row and there is only one column?
Everything I found on the net seems to be about the opposite, making a UITableView be a UICollectionView
Actually, its very simple. Just make the width of the UICollectionViewCell equal to the width of the view.
I have a table with different cells and I need to add a scroller view with special UI in some cells:
I need to develop the UI which you can see in section 0.
So my questions are:
How can I add a scroller view?
How can I load data only for those items which are shown right now?
How can I change the width of "Line" column after scrolling to the right?
I'll answer as best I can with some starting pointers for you...
You need to subclass UITableViewCell and in your subclasses drawRect method you should add a UIScrollView to the contentView.
Not totally sure what you mean here, please expand.
In your new table cell, set it as the delegate of the scroll view you implemented, then you''ll get callbacks when the scrollview scroll with the contentOffset value, which you can use to calculate how much to grow or shrink the line items.
Take this about page for Things:
I'm having trouble creating something similar. I just want a UITableView under a UIView with a UIImageView and a UILabel in it.
If I use a UIViewController and so I can position the UITableView downward, I get this error: "Static table views are only valid when embedded in UITableViewController instances."
If I use a UITableViewController with a grouped style and use contentInset on self.tableView to move it down ([self.tableView setContentInset:UIEdgeInsetsMake(150,0,0,0)];) I can't figure out how to place a view above it. If I try to attach anything to self.view it crashes (obviously). Same happens if I attach anything to self.tableView.
I then tried making the UIView the header of my UITableView section (I only need one section) but I can't get it to move up enough. It just sits inside the UITableView almost.
How do I have a UITableView (grouped style) exist with a UIView above it?
This can be achieved easily using the tableHeaderView property of UITableView. If you are using Interface Builder (which it looks like you are), then you can just drag a UIView above the table view and it will be set as the table's header view. All you need is a UITableViewController; no need for UIViewController and manually laying it out.
That's because the view probably isn't placed on top of the table but rather within the table's section 0 header. Or, even more likely, the view in question is just a regular UITableViewCell with a 0 alpha background.
Either of these options would allow the top view to be scrolled out of frame as the user scrolls under every condition.
I recommend [MDAboutController] (https://github.com/mochidev/MDAboutController)
It's easy to integrate and you don't have to waste any time configuring the UITableView.
I have an UICollectionView where the items can modify at run time it's height.
The problem is that when an item is higher than another, the item are surrounded by a lot o blank space.
I'm looking for a property that create this:
and I want use UICollectionView not github example or third part implementation.
Thanks.
I don't believe UICollectionViewFlowLayout behaves this way. Try to reload your collection view after modifying the height or returning a different value for that cell in collectionView:layout:sizeForItemAtIndexPath: and see if the gap fills. Otherwise, I'd recommend using a custom UICollectionViewLayout subclass.
This class might fit this purpose properly - a UICollectionViewLayout subclass to work with your collection view:
https://github.com/aceisScope/WaterflowView/blob/master/WaterFlowDisplay/WaterFlowLayout.h
I have tried looking for an answer to this question but so far I haven't got any luck.
Context
I have a UITableView inside a standard UIViewController (NOT a UITableViewController..). I have subclassed UITableViewCell and all the cells in the tableview are from the same class.
Requirement
I would like to find an efficient way to resize the cells based on the scrolling of the tableview. For example, when the cell is at the bottom of the visible list, the height is X. When the cell moves up on the screen, its height should proportionally increase to 2X.
Additional Info
I am close to just ditch the UITableView way and start making my own control that would implement such a feat by subclassing a UIScrollView. However, I would like to see if it is possible before going this path. I did see some very interesting SO posts but nothing that would put me on the right path.
Any hint or help would be highly appreciated.
You would need to respond to the scroll view delegate method scrollViewDidScroll: and implement it to record the cell at the top of the table view and reload the table view. Then your table view delegate method tableView:heightForRowAtIndexPath: sets the cell height by the relationship between the index path and the top cell index path.
Your main issue is performance while reloading the table view all the time.
If you wanted to roll your own solution it would be along the lines of the above description anyway, but you would be able to be more efficient than the table view as the table view will call the tableView:heightForRowAtIndexPath: method once for every row for every reload in order to calculate the total height of the table content.