apploft / aplexpandablecollectionview Goto Github PK
View Code? Open in Web Editor NEWUICollectionView subclass with vertically expandable and collapsible sections
License: MIT License
UICollectionView subclass with vertically expandable and collapsible sections
License: MIT License
in objective-c
not works
in swift:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: self.view.frame.size.width, height: 120)
}
not works
:(
only i can change size item with this code:
let layout:APLExpandableSectionFlowLayout = self.collectionView.collectionViewLayout as! APLExpandableSectionFlowLayout
layout.itemSize = CGSizeMake(self.view.frame.size.width, 120);
layout.minimumLineSpacing = 4
layout.scrollDirection = .Vertical
layout.sectionInset = UIEdgeInsetsMake(8, 8, 0, 8);
but i need to do by NSIndexPath
Hello,
I have extended the Demo to display a + or a - label in the section cells. I use cellForItemAtIndexPath to hide the label on item cells:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
APLCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"APLCollectionViewCell" forIndexPath:indexPath];
if (indexPath.item == 0) {
cell.label.text = [NSString stringWithFormat:@"Section %li", (long)indexPath.section + 1];
cell.backgroundColor = [UIColor colorWithRed:58./255. green:165./255. blue:192./255. alpha:1.];
cell.indentView.hidden = YES;
cell.label_OnOff.text = @"+";
} else {
cell.label.text = [NSString stringWithFormat:@"Item %li", (long)indexPath.row];
cell.backgroundColor = [UIColor colorWithRed:58./255. green:165./255. blue:192./255. alpha:.5];
cell.indentView.hidden = NO;
[cell.label_OnOff setHidden:YES];
}
return cell;
}
To switch between + and - I implemented the delegate methods:
- (void)collectionView:(UICollectionView *)collectionView didCollapseItemAtIndexPath:(NSIndexPath *)indexPath
{
APLCollectionViewCell *cell = (APLCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
cell.label_OnOff.text = @"+";
}
- (void)collectionView:(UICollectionView *)collectionView didExpandItemAtIndexPath:(NSIndexPath *)indexPath
{
APLCollectionViewCell *cell = (APLCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
cell.label_OnOff.text = @"-";
}
As you can see in the screenshot - the label is hidden on some section cells and some item cells. I don't know why this happens - indexPath.item == 0 should check if a specific cell is a section or an item?
It seems that this issue is only present, if cells are not visible. After scrolling down and revealing new cells in the collection view - the label is not visible.
Hi,
I'm trying to change size of individual collection view cell's using "collectionViewLayout:sizeForItemAtIndexPath:" method but it always override it with layout.itemSize value.
itemSize: 375,40
sizeForIndexPath method return size of item which is (50,50). When i check the cell size it's (375,40) again.
Help please..
I want to reset all expanded sections but there is no way.
I have been browsing through the code base, and have a question: I don't really understand why you need the following methods to manipulate the data source:
- (void)addExpandedSection:(BOOL)isExpanded;
- (void)insertExpandedSection:(BOOL)isExpanded atIndex:(NSUInteger)index;
In the end, I could just change my original dataSource
and then call reloadData
to have the same effect, or am I missing something (ignoring that it seems to be the only way to expand #16 atm)? Generally, I don't understand why the collection takes over data source responsibilities. In my eyes it just encourages inconsistencies between the "two" different data sources.
And I wanted to thank you for your work! I wanted to build exactly the same view, but then discovered your solution.
How can we collapse previous selection when a new item a selected.
I want only one item to be in expanded mode at a time
I am using a single collectionview to load three collection of data based on three button clicks.First collection has say 2 items so the datasource gets updated, now if any of the remaining two collections has data more than 2 items, app crashes.
[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]
Hello! Thanks for sharing this! We should add a simple init method to support initing from code:
The expandable collection view uses first item in each section as the "header" and the rest as "items", and it'd be very useful if we could customize the separators for inter-section as well as inter-item (or is there an easy way to do that?)
PS: The response to the previous issue was super fast 👍
I am using a header view for my collection view cells and when I try to implement this my first cell is acting like the button to expand / contract the Collection View cells in that section. Could you please help me how to achieve this using the Collection view header ?
Nvm, just solved this issue. It was due to an error that I made. Thanks anyway!
I was trying to implement adding of new sections when pressing a button. Instead of hard coded value for the number of sections I use an array of items and add new item into that array on button press; after that I call the [collectionView reloadData]; It seems simple enough but unfortunately the app crashes and I cannot manage to reload the data to show the new section. Can you please give me some advice on how could this be achieved in the current implementation. It would be very, very helpful.
I got the same issue of #3 . why is it closed?
It would be quite handy to have the ability to expand and collapse sections programatically.
Since APLSectionTopToBottomFlowLayout is a subclass of UICollectionViewFlowLayout, it naturally makes sense to support UICollectionViewDelegateFlowLayout so that individual item sizes & line spacings can be customized - for example, currently there is no way to make section height larger than item height.
I have around 100 items in the collectionview with picture and text. When opening a section, if there are 10,20 items in the expanded section it's fine. When it contains 100 it takes around 1.5 seconds which is laggy for the user. Any solutions? (Maybe because each time i expand, the whole collectionview loads?) Thank you!
Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.
[!] The ARViewerDemo [Debug]
target overrides the LIBRARY_SEARCH_PATHS
build setting defined in Pods/Target Support Files/Pods-ARViewerDemo/Pods-ARViewerDemo.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the
$(inherited)` flag, or
- Remove the build settings from the target.
[!] The ARViewerDemo [Release]
target overrides the LIBRARY_SEARCH_PATHS
build setting defined in Pods/Target Support Files/Pods-ARViewerDemo/Pods-ARViewerDemo.release.xcconfig'. This can lead to problems with the CocoaPods installation - Use the
$(inherited)` flag, or
- Remove the build settings from the target.
Hi, Expert,
Is it doable as a new feature: Horizontal expandableCollectionView
BR
Steven
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.