GithubHelp home page GithubHelp logo

sunilkumar2222 / bubblecollectionviewlayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mindinventory/bubblecollectionviewlayout

0.0 1.0 0.0 50 KB

Create bubble layout of UICollectionView using custom layout

License: MIT License

Objective-C 53.18% Swift 46.82%

bubblecollectionviewlayout's Introduction

BubbleCollectionViewLayout

Used to get layout like following screens in UICollectionView using custom layout.

bubble_portrait

bubble_landscape

Requirements

Minimum OS 8.1 and later

Manual Installation

You can directly add Below the source files from Class folder to your project.

Objective C

  1. MIBubbleCollectionViewCell.h
  2. MIBubbleCollectionViewCell.m
  3. MICollectionViewBubbleLayout.h
  4. MICollectionViewBubbleLayout.m

Swift

  1. MIBubbleCollectionViewCell.swift
  2. MICollectionViewBubbleLayout.swift

Introduce

MICollectionViewBubbleLayout is subclass of UICollectionViewFlowLayout with the custom layout.

Usage

The easy way is to use UICollectionViewFlowLayout as it is. You can also subclass it if you intend to change the default behaviour.

Here is the instruction of how to use UICollectionViewFlowLayout in the Storyboard.

  1. Add native UICollectionView to the storyboard, establish relationships with its view controllers.
  2. Add UICollectionViewCell in the UICollectionView to the storyboard. 3)Chose the MIBubbleCollectionViewCell as a custom class inside the UICollectionViewCell to the storyboard. Configuration for change DefaultInterItemSpacing & DefaultLineSpacing of collecttionview cell you just have to change the value of below two constant in MICollectionViewBubbleLayout.h

#define kDefaultInterItemSpacing 5.0f

#define kDefaultLineSpacing 5.0f

Objective C -

  1. Add "MICollectionViewBubbleLayout" ObjectiveC files to your project.

  2. Conform delegate "MICollectionViewBubbleLayoutDelegate" to your class.

  3. Set bubble layout in collectionview.

     MICollectionViewBubbleLayout *layout = [[MICollectionViewBubbleLayout alloc] initWithDelegate:self];
     [layout setMinimumLineSpacing:6.0f];
     [layout setMinimumInteritemSpacing:6.0f];
     [collVData setCollectionViewLayout:layout];
    
  4. Implement MICollectionViewBubbleLayoutDelegate method to return size according to your text content.

     - (CGSize)collectionView:(UICollectionView *)collectionView itemSizeAtIndexPath:(NSIndexPath *)indexPath {
    
         NSString *title = arrData[indexPath.row];
         CGSize size = [title sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15]}];
         size.width = ceilf(size.width + CTitlePadding * 2);
         size.height = 24;
    
         //...Checking if item width is greater than collection view width then set item width == collection view width.
         if (size.width > collectionView.frame.size.width)
             size.width = collectionView.frame.size.width;
          return size;
     }
    

Swift -

  1. Add "MICollectionViewBubbleLayout" Swift file to your project.

  2. Conform delegate "MICollectionViewBubbleLayoutDelegate" to your class.

  3. Set bubble layout in collectionview.

     let bubbleLayout = MICollectionViewBubbleLayout()
     bubbleLayout.minimumLineSpacing = 6.0
     bubbleLayout.minimumInteritemSpacing = 6.0
     bubbleLayout.delegate = self 
     collVData.setCollectionViewLayout(bubbleLayout, animated: false)
    
  4. Implement MICollectionViewBubbleLayoutDelegate method to return size according to your text content.

     func collectionView(_ collectionView:UICollectionView, itemSizeAt indexPath:NSIndexPath) -> CGSize
     {
         let title = arrData![indexPath.row] as! NSString
         var size = title.size(withAttributes: [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Bold", size: 15)!])
         size.width = CGFloat(ceilf(Float(size.width + CGFloat(kItemPadding * 2))))
         size.height = 24
     
         //...Checking if item width is greater than collection view width then set item width == collection view width.
         if size.width > collectionView.frame.size.width {
             size.width = collectionView.frame.size.width
         }
     
         return size;
     }
    

LICENSE!

BubbleCollectionViewLayout is MIT-licensed.

Let us know!

We’d be really happy if you send us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding our work.

bubblecollectionviewlayout's People

Contributors

pratikmi avatar

Watchers

James Cloos avatar

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.