Tag: uicollectionview

如何更改UICollectionView中的单元格之间的空间?

我想减less行中的单元格之间的大小。 现在看起来像: 我正在尝试这个,以减less它们之间的大小: let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.sectionInset = UIEdgeInsets(top: 20, left: 2, bottom: 10, right: 2) layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 0 但它不能帮助我。 我做错了什么?

iOS设置为0时,UICollectionView间距仍然存在 – 如何设置单元格之间没有间距

我有一个简单的UICollectionView,我已经在InterfaceBuilder中设置了0的间距,但是当我用单元填充集合视图时,仍然有一些间距。 有没有什么特别的,并不是很明显,我需要做的,以实际上看到一个0间距collectionview单元格超出设置它有0间距? 谢谢。 编辑*一些代码: – (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.backgroundColor = [UIColor clearColor]; UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(2, 2, cell.frame.size.width -4, cell.frame.size.height -4)]; lbl.backgroundColor = [UIColor clearColor]; lbl.font = [UIFont boldSystemFontOfSize:20]; lbl.text = [NSString stringWithFormat:@"$%0.0f", [[amountsArray objectAtIndex:indexPath.row] floatValue]]; lbl.textAlignment = NSTextAlignmentCenter; lbl.layer.borderWidth = 1; [cell addSubview:lbl]; […]

尝试覆盖UICollectionViewCell Swift中的“select”以获得自定义select状态

我正在尝试在UICollectionView中为我的单元格实现自定义select样式。 尽pipe很容易在didSelect和didDeSelect方法中手动执行此操作,但我希望通过操作UICollectionViewCell中的“selected”variables来实现此目的。 我有这个代码: override var selected: Bool { get { return super.selected } set { if newValue { self.imageView.alpha = 0.5 println("selected") } else if newValue == false { self.imageView.alpha = 1.0 println("deselected") } } } 现在,当我select一个单元格时,单元格会突出显示,但是“selected”被打印两次,取消select不起作用(即使两个UICollectionView方法都已经实现)。 我将如何去做这件事? 谢谢!

是完全静态的UICollectionView可能吗?

在UITableView中,完全静态的tableViewconfiguration是可能的。 您可以断开UITableView的数据源,并使用IB将每个单元格放在故事板(或xib)上。 我用UICollectionView尝试了同样的事情。 断开UICollectionView的数据源。 将每个单元放在故事板上的UICollectionView上。 我没有任何错误地build立它。 但它没有工作。 细胞根本不显示。 没有数据源的UICollectionView是可能的吗?

UICollectionView cellForItemAtIndexPath是零

我有一个函数,更新现有的UICollectionView。 UICollectionView被创build,我可以看到它,但是当我想访问它的单元格来更新它时,它们是零。 -(void)finishExam{ for (int i = 0; i < [self.questionsOverviewCollection numberOfItemsInSection:0]; i++) { NSLog(@"self.questionsOverviewCollection – %@",self.questionsOverviewCollection); NSLog(@"cell – %@",[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]); NSLog(@"overviewCell – %@",(OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]); NSLog(@"numOfCells – %d", [self.questionsOverviewCollection numberOfItemsInSection:0]); OverviewCell *cell = (OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; [cell finishExam]; } } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ OverviewCell *cell = (OverviewCell*)[collectionView […]

放大一个二维UICollectionView

我创build了一个横向和纵向的UICollectionView 。 它有不同的UICollectionViewCells 。 一切都是正确的。 现在我正在努力使其变得可zoomable 。 UICollectionViewCells也正确resize。 每当UIPinchGesture发生时,我itemSize在UICollectionViewLayout依赖项的scale设置itemSize 。 TestLayout *layout = (TestLayout *) self.collectionViewLayout; CGSize newItemSize = CGSizeMake(_sizeItem.width * gesture.scale, _sizeItem.height * gesture.scale); [layout setItemSize:newItemSize]; 在这里你可以看到我在CustomLayout中调用的setItemSize方法。 – (void)setItemSize:(CGSize)itemSize { if (CGSizeEqualToSize(self.itemSize, itemSize)) return; _itemSize = itemSize; // [self prepareLayout]; [self invalidateLayout]; } 我的问题是知道,所有项目resize到右下angular,我不知道如何专注于我的UIPinchGesture上的元素。 每次gesture发生时,我都试图改变contentOffset : CGPoint posInView = [gesture locationInView:self]; CGPoint pointPinchTouch = […]

删除UICollectionView边缘的单元格 – 单元格不会在滚动后立即出现

考虑一个标准的垂直滚动stream布局,填充足够的单元格以引起滚动。 当滚动到底部时,如果您删除一个项目,以便收集视图的内容大小必须缩小以容纳新的项目数(即删除最后一行的最后一项),那么从顶部隐藏。 在删除animation结束时,顶部一行出现没有animation – 这是一个非常不愉快的效果。 在慢动作中: 重现真的很简单: 创build一个新的单个视图项目,并将默认的ViewController更改为UICollectionViewController的子类 将UICollectionViewController添加到使用标准stream布局的故事板,并将其类更改为ViewController 。 给单元格原型标识符“单元格”和一个200×200的大小。 将下面的代码添加到ViewController.m : @interface ViewController () @property(nonatomic, assign) NSInteger numberOfItems; @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; self.numberOfItems = 19; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.numberOfItems; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { return [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; } – (void)collectionView:(UICollectionView *)collectionView […]

如何创build像App Store中的精选页面的布局?

我是iOS开发新手。 基于我的假设,App Store中的Feature页面是使用UITableView和UICollectionView的组合创build的。 但是如何在理论和代码上做到这一点? 我知道这有点含糊,因为描述起来很难,但我只是需要一些人来帮我解释一下。 对于这种情况,我会尝试使用这些命名: 1.顶部,这是一个展示应用程序横幅的视图,人们可以滑动它来查看另一个横幅。 2.中间部分,可以水平滚动的视图。 (最佳新应用程序,最佳新游戏等)。 3.底部,从快速链接开始到底部。 问题: 1.滚动指示器从根视图的顶部向导开始,这是正常的,但是: 一个。 当我们把它卷起来的时候,这个反弹就是从中间部分开始的。 怎么做? 顶部和中间部分是分开的视图? 但是如果顶部和中间部分是分离的视图,滚动指示器如何从根视图的顶部指南开始? (分离视图意味着视图应该有不同的滚动指标,除非它实际上是UIScrollView的子视图)。 湾 当我们向下滚动时,没有任何浮动。 所以它看起来像整个页面是一个单一的滚动视图的子视图,但反弹是从中间部分开始。 如何在整个页面只有一个滚动指示器的情况下创build弹性效果? 2.在中间部分,有几个横向滚动方向的集合视图。 是最好的方式来创build它,就像使用UITableView与UICollectionView里面的单元格? 它看起来像是这样创build的,但是: 一个。 这是最有效的方法吗? 湾 因为我的第一个问题是我的困惑。 底部有与中间部分不同的分离器。 中间部分有缩进,而底部没有。 我怎么能这样做,如果这是一个UITableView? 我的整个问题是如何创build一个这样的布局。 如果你不能帮我提供一些很好的示例代码,请向我解释如何做到这一点的概念或理论。 如果整个答案只是我必须从头开始使用垂直/水平UIScrollView来创build它,那很好。 我只是想确保这一点,因为我试图避免处理创build手动拼贴。

UICollectionViewCell使用原型尺寸

我有一个UICollectionView有三个不同的原型单元格,每个原型单元格都通过Storyboard设置不同的高度。 在运行时,集合视图使用自己的单元大小,忽略我的故事板。 我目前正在使用collectionView:layout:sizeForItemAtIndexPath:用一对条件来设置每个CGSize直。 有没有更好的方法来设置单元格大小? 我似乎无法获取每个单元格的Storyboard尺寸,而CGSizeMake似乎太硬编码,并且不够灵活。

在uitableviewcell里面使用uicollectionview

我无法解决下一个问题。 我想要显示20个表格单元格,每个单元格包含一个唯一的UICollectionView 。 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *package=[_packageList objectAtIndex:indexPath.row]; static NSString *CellIdentifier = @"package"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UICollectionView *cellImageCollection=(UICollectionView *)[cell viewWithTag:9]; cellImageCollection.restorationIdentifier=[NSString stringWithFormat:@"%li", (long)indexPath.row, nil]; cellTracking.text=[NSString stringWithFormat:@"Row #%li",(long)indexPath.row]; return cell; } -(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ int row=[collectionView.restorationIdentifier intValue]; return [[[_packages objectAtIndex:row] valueForKey:@"imageGallery"] count]; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ […]