我们如何才能实现集合视图的外观,如下图所示?

时间:2016-11-23 06:58:42

标签: ios swift3

I need such a kind of appearance in my app wherein a cell will be at the centre and part of cells on both sides. 此外,我需要为该集合视图启用循环滚动。 有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

enter image description here 首先在各自的ViewController中拖动集合视图,然后在活动检查器中选择滚动方向为Horizo​​ntal。 enter image description here

   func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
        return collectionView.frame.size.width/2

    }
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake((collectionView.frame.size.height) , (collectionView.frame.size.height))
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return img_Arr.count
    }

    // make a cell for each cell index path
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        // get a reference to our storyboard cell
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell3", forIndexPath: indexPath) as! ImageCaptureCell
        cell.CapturedImage.clipsToBounds = true
        cell.contentView.frame = cell.bounds
        let capt = UIImage(data:img_Arr[indexPath.row] as! NSData,scale:1.0)
        cell.CapturedImage.image = capt

        return cell
    }

    // MARK: - UICollectionViewDelegate protocol

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        // handle tap events
        print("You selected cell #\(indexPath.item)!")
    }

    func collectionView(collectionView: UICollectionView, didHighlightItemAtIndexPath indexPath: NSIndexPath)
    {
        let cell = collectionView.cellForItemAtIndexPath(indexPath)
        //cell?.backgroundColor = UIColor.redColor()
    }

    // change background color back when user releases touch
    func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath)
        //        cell?.backgroundColor = UIColor.yellowColor()
    }

另外,在顶部提供搜索栏,并将表格委托给表格

相关问题