GithubHelp home page GithubHelp logo

customcollectionviewlayout's Introduction

CustomCollectionViewLayout

 

Expected result

Implementation

Prease find full tutorial at the following link. In this tutorial, I'm going to show you, how to create a custom UICollectionView layout.

customcollectionviewlayout's People

Contributors

dmytrobrovkin avatar

Stargazers

Sebastien Menozzi avatar lmarceau avatar Imrul Kayes Shamil avatar Álvaro García León avatar Cary Miller avatar Lupu Nicolae Teodor avatar Alex avatar  avatar  avatar Amit Chowdhury avatar Rahul Chandnani avatar  avatar Haris Budi E avatar sean_xie avatar Shankar avatar Bassem Tourky avatar Pablo Romero avatar  avatar Antonin Biret avatar

Watchers

James Cloos avatar Denys avatar  avatar

customcollectionviewlayout's Issues

Implement To Create Layout like Instagram Explore

Hi, I wanna implement your code to create UICollectionView Layout like Instagram Explore. It has to has ability to detect page number. One page consist of 12 items. The default UICollectionView cell's shape is square. But, the UICollectionView cell in odd or even position in odd or even page number has to be 2x bigger than the other cells in the page. To create that came with this algorithm:

       switch (indexPath.item%12, pageNumber/2) {
        case (0, 1), (1,0):
            itemWidth = itemWidth * 2
            itemHeight = itemWidth
        default:
            break
        }

I implement that code in function calculateItemFrame(indexPath: IndexPath, columnIndex: Int, columnYoffset: CGFloat, pageNumber: Int) in OCTGalleryLayout_v1.swift file (I got this file from this repo). I also modified the code in that function to make a square UICollectionView cell. So, the code in that function become like this:

override func calculateItemFrame(indexPath: IndexPath, columnIndex: Int, columnYoffset: CGFloat, pageNumber: Int) -> CGRect {
        //let rowIndex = indexPath.item / totalColumns
        //let halfItemHeight = (_itemSize.height - interItemsSpacing) / 2
        
        //Resolving Item height
        var itemHeight = _itemSize.height
        var itemWidth = _itemSize.width
        
        switch (indexPath.item%12, pageNumber/2) {
        case (0, 1), (1,0):
            itemWidth = itemWidth * 2
            itemHeight = itemWidth
        default:
            break
        }

        // By our logic, first and last items in reduced height column have height divided by 2.
        /*if (rowIndex == 0 && columnIndex == kReducedHeightColumnIndex) || self.isLastItemSingleInRow(indexPath) {
            itemHeight = halfItemHeight
        }*/
        
        return CGRect(x: _columnsXoffset[columnIndex], y: columnYoffset, width: itemWidth, height: itemHeight)
    }

The result is not as expected, yet.

Could you give me some insight how to do this?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.