Tag: uicollectionview

UICollectionView只显示第一个项目

我正在做一个类似于video专辑的项目。 在这我使用UICollectionView来显示这些video的拇指图像。 最糟糕的是我不应该使用storyboard或xib文件。 我试图以编程方式做到这一点。 我目前正在处理这个代码: – (void)viewDidLoad { i = 0; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; [layout setItemSize:CGSizeMake(self.view.frame.size.width/2.5,self.view.frame.size.width/2.5)]; collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; [collectionView setDataSource:self]; [collectionView setDelegate:self]; collectionView.backgroundColor = [UIColor whiteColor]; [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"]; [self.view addSubview:collectionView]; [super viewDidLoad]; } 我已经给numberOfSectionsInCollectionView返回1和[myArray count]返回numberOfItemsInSection 。 -(UICollectionViewCell *) collectionView:(UICollectionView *)cV cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = […]

调整细胞大小适合所有屏幕?

我试图让我的应用程序适合所有screenize,但是我不知道如何。 是否可以根据屏幕调整单元格大小? 目前我只是configuration我的UICollectionView如下: func numberOfSections(in collectionView: UICollectionView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of items return fields.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let […]

用Swift创build一个分页UICollectionView

我试图创build一个UICollectionView与分页,并且每个项目的最大宽度是250点,我已经设法创build它,但我有2个问题:第一个项目开始不应该是,但在更多的空间开始当我试图刷卡时,总会有东西不让我滑动。 这是它的样子: video链接 这是我的代码: CenterCellCollectionFlowLayout.swift class CenterCellCollectionViewFlowLayout: UICollectionViewFlowLayout { override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? { var attributesToReturn:[UICollectionViewLayoutAttributes] = super.layoutAttributesForElementsInRect(rect) as! [UICollectionViewLayoutAttributes] for var i = 0 ; i < attributesToReturn.count ; i++ { var currentLayoutAttributes: UICollectionViewLayoutAttributes = attributesToReturn[i] var maximumSpacing: CGFloat = 50 let origin: CGFloat if i – 1 >= 0 { let […]

UICollectionView中不同的单元大小

在我的iphone应用程序中,我正在集合视图上显示图像。 我从url获取图片,并通过url获取图片大小。 例如: – 假设有两种图像风景和肖像。我得到的价值P为肖像图像和L为风景图像 如何自定义collectionView单元格的大小?

UICollectionView中的iOS声明失败

我收到错误… *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2372/UICollectionView.m:2249 当试图显示一个UICollectionView。 造成它的线条是… static NSString *CellIdentifier = @"Cell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; 在出列时发生错误。 没有其他的错误,所以我很难知道从哪里开始。 任何人都可以阐明这一点?

UICollectionView多个部分和标题

我正在努力尝试在我的集合视图中做每个部分的标题的多个部分。 我不知道Obj-C,我已经find了大量的教程,但一直没能弄清楚如何将其转换成Swift。 我的所有数据都是静态的,所以我需要的是某种数组或字典,我可以用它来创build多个部分。 我已经有一个集合视图,有1个部分可以工作,所以如果你有任何洞察力或代码多个部分会有所帮助。 我知道如何设置多个部分使用 func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return sectionData.count } 我认为我需要帮助的主要事情是实现这个function func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { } 并设置数据! UICollectionView和UITableView几乎完全一样,所以如果你知道如何在Swift中的UITableView中做多个部分,你的帮助也是赞赏

UICollectionview的自定义页脚视图在swift中

我正在快速写一个客观的C应用程序的min,并决定集合视图效果更好,然后在我的情况下tableview。 所以我有collectionview所有设置正是我想要的,现在我需要添加一个页脚到我的collections视图。 在Objective-C中,对我来说非常简单,我所做的只是创build一个UIView,添加对象,并将其添加到我的tableview中。 self.videoTable.tableFooterView = footerView; 现在我一直试图在我的collections视图中得到类似的解决scheme,但是到目前为止我还没有运气。 有一个简单的.collectionviewFooterView或我可以添加我的UIView? 编辑我发现这里有类似的想法,如果这有助于创build一个答案 编辑 我一直在想方法来实现这一点,所以现在我的想法是使用下面的代码将页脚视图添加到集合视图的末尾: var collectionHeight = self.collectionView.collectionViewLayout.collectionViewContentSize().height footerView.frame = CGRectMake(0, collectionHeight, screenSize.width, 76) 唯一的问题,我有这个解决方法是我需要添加更多的空间到colletionView的contentView,我没有运气 我的解决scheme 我解决了它使用解决方法(不漂亮,但它的工作原理),我添加UIView到uicollectionview使用一个简单的 footerView.frame = CGRectMake(0, collectionHeight – 50, screenSize.width, 50) self.collectionView.addSubview(footerView) 并使用此设置布局插图: alLayout.contentInsets = UIEdgeInsetsMake(2, 2, 52, 2)

在故事板中收集视图的末尾添加button

我有一个故事板中的UICollectionViewController 。 我知道如何添加单元格并修改它们,但由于某种原因,我无法在我的UICollectionView之后添加任何其他视图或UI元素。 在故事板中有没有办法做到这一点? 如果不是我怎样才能做到这一点编程?

在UICollectionView中search和过滤单元格

我有一个单元格的UICollectionView ,所以有两件事情我想用这个视图来完成。 首先,我想在顶部有一个search栏,可以根据用户的查询过滤单元格。 我只看到用UITableView实现的search栏,那么我该怎么做呢? 此外,我想有一个名为“filter”的button,单击时,将显示一个popup式视图控制器与一系列checkbox及其值。 因此,如果我用户select了checkbox,则一旦用户按下位于右上angular的“完成”button,它将根据他们的检查过滤单元。 如果用户不决定过滤他的search,那么左上angular也会有一个“取消”button。 我的UICollectionView的图片: 我的代码 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; backpackIcons *item = _backpackItems[indexPath.row]; NSString *photoURL = item.image_url; NSString *quality = item.quality; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; UIImageView *itemImageView = (UIImageView *)[cell viewWithTag:100]; itemImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoURL]]]; [itemImageView setBackgroundColor:Rgb2UIColor(60, 53, 46)]; if([[NSString […]

caching图像和UICollectionView

我对Objective-C很新,所以希望这一切都合情合理。 我已经从服务器下载图像,并在collectionView cellForItemAtIndexPath:方法的图像视图中显示它们。 我面临的问题是图像看起来不是caching。 看起来每次单元格被重新使用时,服务器的相关图像将被重新下载。 在我的viewDidLoad方法我创build一个NSMutableDictionary: imageDictionary = [[NSMutableDictionary alloc]initWithCapacity:50.0]; 从阅读文档,看类似问题的答案,我认为这一点,加上下面的代码就足够了。 我已经在这一两天了,我知道有一些我失踪或一个概念,我不抓住。 #pragma mark – UICollectionView Data Source – (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;{ NSLog(@"Begin retrieving photos"); return [self.photos count]; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;{ CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath]; cell.imageView.image = nil; if (cell.imageView.image == nil) { dispatch_queue_t […]