Giter VIP home page Giter VIP logo

coder-zjq / jqcollectionviewalignlayout Goto Github PK

View Code? Open in Web Editor NEW
70.0 2.0 13.0 3.22 MB

A custom layout object based on flow layout. Added supports for horizontal, vertical alignment and RTL direction of collection view items.(available for both UICollectionView and NSCollectionView)

License: MIT License

Objective-C 84.46% Ruby 10.13% Swift 5.41%
uicollectionviewflowlayout right-to-left align-left align-right center left-to-right alignment uicollectionviewlayout nscollectionviewflowlayout uicollectionview

jqcollectionviewalignlayout's Introduction

English | 中文说明

JQCollectionViewAlignLayout

Version License Platform

A custom layout object based on flow layout, that supports setting horizontal, vertical alignment and RTL(right to left) direction of collection view items.

(available for both UICollectionView and NSCollectionView)

Example

To run the example project, clone the repo, and run pod install from the Examples directory first. Then open JQCollectionViewAlignLayout.xcworkspace with Xcode and choose a scheme below:

iOS

macOS

tvOS

Alignments and Directions

Horizontal Demo Image
JQCollectionViewItemsHorizontalAlignmentFlow(default)
JQCollectionViewItemsHorizontalAlignmentLeft
JQCollectionViewItemsHorizontalAlignmentCenter
JQCollectionViewItemsHorizontalAlignmentRight
JQCollectionViewItemsHorizontalAlignmentFlowFilled
Vertical Demo Image
JQCollectionViewItemsVerticalAlignmentCenter(default)
JQCollectionViewItemsVerticalAlignmentTop
JQCollectionViewItemsVerticalAlignmentBottom
Direction Demo Image
JQCollectionViewItemsDirectionLTR(default)
JQCollectionViewItemsDirectionRTL

Requirements

iOS 6.0 +

macOS 10.11 +

tvOS 9.0 +

Installation

JQCollectionViewAlignLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'JQCollectionViewAlignLayout'

Usage

  1. Init the collectionView with JQCollectionViewAlignLayout:
  • by code:
// UICollectionView
JQCollectionViewAlignLayout *layout = [[JQCollectionViewAlignLayout alloc] init];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];

// NSCollectionView
JQCollectionViewAlignLayout *layout = [[JQCollectionViewAlignLayout alloc] init];
NSCollectionView *collectionView = ...;
collectionView.layout = layout;
  • or setup in the Interface Builder:

  1. Setup the alignment and direction:
  • Property(for all sections):
layout.itemsHorizontalAlignment = JQCollectionViewItemsHorizontalAlignmentLeft;
layout.itemsVerticalAlignment = JQCollectionViewItemsVerticalAlignmentCenter;
layout.itemsDirection = JQCollectionViewItemsDirectionLTR;
  • Protocol(for each section):
// 1. conforms to protocol JQCollectionViewAlignLayoutDelegate
@interface JQViewController () < UICollectionViewDataSource, JQCollectionViewAlignLayoutDelegate>

@end

@implementation JQViewController
// 2. implement the protocol method
- (JQCollectionViewItemsHorizontalAlignment)collectionView:(UICollectionView *)collectionView layout:(JQCollectionViewAlignLayout *)layout itemsHorizontalAlignmentInSection:(NSInteger)section {
  // return the JQCollectionViewItemsHorizontalAlignment in section.
}

- (JQCollectionViewItemsVerticalAlignment)collectionView:(UICollectionView *)collectionView layout:(JQCollectionViewAlignLayout *)layout itemsVerticalAlignmentInSection:(NSInteger)section {
  // return the JQCollectionViewItemsVerticalAlignment in section.
}

- (JQCollectionViewItemsDirection)collectionView:(UICollectionView *)collectionView layout:(JQCollectionViewAlignLayout *)layout itemsDirectionInSection:(NSInteger)section {
  // return the JQCollectionViewItemsDirection in section.
}

@end

The others are same as UICollectionViewFlowLayout/NSCollectionViewFlowLayout.

Author

coder-zjq, [email protected]

License

JQCollectionViewAlignLayout is available under the MIT license. See the LICENSE file for more info.

jqcollectionviewalignlayout's People

Contributors

coder-zjq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jqcollectionviewalignlayout's Issues

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.