• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

FSQCollectionViewAlignedLayout is a generic collection view layout designed to be very flexible and configurable. It's goal is to save its users from having to write their own custom layout classes every time UICollectionViewFlowLayout is not appropriate for their view.

FSQCollectionViewAlignedLayout

A simple, generic collection view layout with multiple customization options.

Overview

FSQCollectionViewAlignedLayout is a generic collection view layout designed to be very flexible and configurable. It's goal is to save its users from having to write their own custom layout classes every time UICollectionViewFlowLayout is not appropriate for their view.

The layout acts like a very simple typesetter, with each cell being like a "word" or font glyph, and each section being a "paragraph" with multiple lines of cells.

The class is thoroughly documented in its header (which should be automatically parsed and available through Xcode's documentation popovers), but this file includes an overview of its features.

Setup

Aligned Layout is only two files with no external dependencies, so it should be quick and easy to add to your project. Simply add the files to your project, and then you can start using aligned layout with your collection views.

We recommend using git submodules to link your repo against this one for easy updating when future versions are released.

Section Attributes

The FSQCollectionViewAlignedLayoutSectionAttributes class defines the properties for customizing the layout of your collection view sections.

If all your sections have the same attributes, you can set the defaultSectionAttributes property on the layout. Alternatively you can implement the following method in your delegate to return different attributes for each section:

- (FSQCollectionViewAlignedLayoutSectionAttributes *)collectionView:(UICollectionView *)collectionView
                                                             layout:(FSQCollectionViewAlignedLayout *)collectionViewLayout
                                        attributesForSectionAtIndex:(NSInteger)sectionIndex;

The follow section attributes are available:

FSQCollectionViewHorizontalAlignment horizontalAlignment — This property aligns each line of the collection view horizontally, relative to the entire section. The options are Left, Right, and Center

FSQCollectionViewVerticalAlignment verticalAlignment — If cells on the same line are different heights, this property aligns them vertically relative to each other. The options are Top, Bottom, and Center

CGFloat itemSpacing — This is the horizontal space in points between cells on the same line.

CGFloat lineSpacing — This is the vertical space in points between the bottom of one line in the paragraph and the top of the next. The bounding box of each line is considered to be a rectangle that exactly encompasses every cell on the line. Because of this, if cells on the same line are not of uniform height, some of them may have more vertical space between them and the next or previous line (depending on many other factors, such as vertical alignment and cell insets).

UIEdgeInsets insets — This is the spacing in points around all four edges of the section. The bounding box of the section is considered to be a rectangle that exactly encompasses every line in the section.

Instances of this class are immutable, so you must define all properties on creation. There are two class methods for creating new attributes objects

+ (instancetype)withHorizontalAlignment:(FSQCollectionViewHorizontalAlignment)horizontalAlignment
                      verticalAlignment:(FSQCollectionViewVerticalAlignment)verticalAlignment;

This method creates a new section attributes object with the specified alignments. It defaults to item and line spacings of 5 points and has no insets (UIEdgeInsetsZero).

+ (instancetype)withHorizontalAlignment:(FSQCollectionViewHorizontalAlignment)horizontalAlignment
                      verticalAlignment:(FSQCollectionViewVerticalAlignment)verticalAlignment
                            itemSpacing:(CGFloat)itemSpacing
                            lineSpacing:(CGFloat)lineSpacing
                                 insets:(UIEdgeInsets)insets;

This method is the same as above but lets you specify your own spacings and insets.

Additionally the class defines four shared pointers to commonly used alignments for convenience.

+ (FSQCollectionViewAlignedLayoutSectionAttributes *)topLeftAlignment;
+ (FSQCollectionViewAlignedLayoutSectionAttributes *)topCenterAlignment;
+ (FSQCollectionViewAlignedLayoutSectionAttributes *)topRightAlignment;
+ (FSQCollectionViewAlignedLayoutSectionAttributes *)centerCenterAlignment;

Cell Attributes

The FSQCollectionViewAlignedLayoutCellAttributes class defines the properties for customizing the layout of your collection view cells.

If all your cells have the same attributes, you can set the defaultCellAttributes property on the layout. Alternatively you can implement the following method in your delegate to return different attributes for each cell:

- (FSQCollectionViewAlignedLayoutCellAttributes *)collectionView:(UICollectionView *)collectionView
                                                          layout:(FSQCollectionViewAlignedLayout *)collectionViewLayout
                                    attributesForCellAtIndexPath:(NSIndexPath *)indexPath;

The following cell attributes are available

UIEdgeInsets insets — This is the spacing in points around all four edges of the cell. For layout positioning purposes, these insets are added to the cell's size. For example, a 50x50 point cell with 5 point insets on all four sides will be laid out as if it was a 60x60 point cell. However, the actual UICollectionViewCell class will end up being the correct size you reported it as being.

BOOL shouldBeginLine — If YES, this will force the cell to be the first cell on the line if it would not otherwise have been laid out that way.

BOOL shouldEndLine — If YES, this will force the cell to be the last cell on the line if it would not otherwise have been laid out that way.

BOOL startLineIndentation — If YES and the section's alignment is Left or Right, this will force all future lines to line up with the left or right edge of this cell respectively. The available width of all future lines will be lowered and padding will be added to the appropriate side to inset them. The indentation starts at the actual edge of the cell, not including insets. There can be only one indentation at a time per section; a future cell in the same section with indentation will override a previous one.

Instances of this class are immutable, so you must define all properties on creation. There is one class method for creating new attributes objects:

+ (instancetype)withInsets:(UIEdgeInsets)insets
           shouldBeginLine:(BOOL)shouldBeginLine
             shouldEndLine:(BOOL)shouldEndLine
      startLineIndentation:(BOOL)startLineIndentation;

This method creates a new cell attributes object with the specified values.

Additionally the class defines a shared pointer to a default attributes object with no insets, no line breaks, and no indentation.

+ (FSQCollectionViewAlignedLayoutCellAttributes *)defaultCellAttributes;

Cell Sizing

If all your cells are the same size, you can set the defaultCellSize property on the layout. Alternatively, you can implement the following method in your delegate to return different sizes for each cell:

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(FSQCollectionViewAlignedLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
      remainingLineSpace:(CGFloat)remainingLineSpace;

This mirrors the sizing delegate method used by UICollectionViewDelegateFlowLayout, but with the addition of the remainingLineSpace parameter. This parameter contains the amount of horizontal space in points remaining on the current line that is being laid out. If you return a size whose width is less than or equal to remainingLineSpace it will therefore be laid out on the same line (barring any other cell attributes that might change this, such as line breaks). This can be useful when you want to calculate a height based on width to fill up space on the rest of the line (e.g. for text or image sizing purposes).

Top Level Properties

The layout has the following top level properties for customizing the entire collection view.

CGSize defaultCellSize — This size is used for all cells if the corresponding delegate method is not implemented. It defaults to 100x100 points.

FSQCollectionViewAlignedLayoutSectionAttributes *defaultSectionAttributes — This attributes object is used for all sections if the corresponding delegate method is not implemented. If not set, the default value is FSQCollectionViewAlignedLayoutSectionAttributes topLeftAlignment].

FSQCollectionViewAlignedLayoutCellAttributes *defaultCellAttributes — This attributes object is used for all cells if the corresponding delegate method is not implemented. If not set, the default value is [FSQCollectionViewAlignedLayoutCellAttributes defaultCellAttributes].

CGFloat sectionSpacing — This is the vertical spacing in points between the bottom of one section and the top of the next. The bounding box of the section is considered to be a rectangle that exactly encompasses every line in the section. If not set, the default value is 10 points.

UIEdgeInsets contentInsets — This is the spacing in points around all four edges of the collection view content. The bounding box is a rectangle that exactly encompasses every section in the collection. If not set, the default value is 5 point spacing for all edges.

BOOL shouldPinSectionHeadersToTop — This controls whether the current top-most section's header gets pinned to the top of the view, similar to how UITableView works when using UITableViewStylePlain. The default value is YES.

Contributors

FSQCollectionViewAlignedLayout was initially developed by Foursquare Labs for internal use. It was originally written by Brian Dorfman (@bdorfman) and Cameron Mulhern, and is currently maintained by Sam Grossberg (@samgro).

More Repositories

1

rogue

MOVED - The project is still under development but this page is deprecated.
Scala
489
star
2

twofishes

MOVED - The project is still under development but this page is deprecated.
Scala
433
star
3

FSNetworking

foursquare iOS networking library
Objective-C
384
star
4

fsqio

A monorepo that holds all of Foursquare's opensource projects
Scala
254
star
5

quattroshapes

Makefile
231
star
6

fongo

faked out in-memory mongo for java
Java
150
star
7

foursquare-android-oauth

Foursquare native authentication makes it easier for your app's users to connect with Foursquare. Unlike web-based OAuth, native authentication re-uses the Foursquare app's user credentials, saving users the hassle of re-logging in to Foursquare within your app.
Java
134
star
8

foursquare-palmpre

A webOS app (Mojo Framework)
JavaScript
105
star
9

foursquare-ios-oauth

Foursquare native authentication makes it easier for your app's users to connect with Foursquare. Unlike web-based OAuth, native authentication re-uses the Foursquare app's user credentials, saving users the hassle of re-logging in to Foursquare within your app.
Objective-C
104
star
10

slashem

A rogue-like DSL for querying SOLR
Scala
103
star
11

FSQLocationBroker

A centralized location manager for your app.
Objective-C
94
star
12

oozie-web

A more pretty, more usable web dashboard for Apache Oozie, written in Scala.
JavaScript
74
star
13

foursquare-fhttp

MOVED - The project is still under development but this page is deprecated.
Scala
44
star
14

FSQCellManifest

A UITableView and UICollectionView delegate and datasource that provides a simpler unified interface for describing your sections and cells.
Objective-C
43
star
15

quiver

An HFile-backed Key-Value Server
Go
42
star
16

hackathon

foursquare hackathonsâ„¢
40
star
17

spindle

MOVED - The project is still under development but this page is deprecated.
Scala
39
star
18

mongo-hdfs-export

Scala
31
star
19

foursquare-app-framework

Framework for building Connected Apps
Python
31
star
20

react-foursquare

Foursquare Library for React
JavaScript
25
star
21

es-scorer-plugin

Plugin to do our scoring in ES
Scala
24
star
22

sites-to-markdown

convert google sites html to markdown
Java
23
star
23

FSQRoutes

URL routing framework for iOS
Objective-C
21
star
24

fsq-studio-sdk-examples

Foursquare Studio is a platform to visualize, unify, enrich, and analyze spatial data on a planetary scale.
Jupyter Notebook
19
star
25

qgis-plugin

Foursquare Studio plugin for QGIS
Python
19
star
26

datasource-plugin-clouderamanager

Cloudera Manager datasource for Grafana 3.x
JavaScript
19
star
27

twitter-util-async

scala-async support for twitter util library
Scala
15
star
28

Place-API-Postman-Collection

Postman collection that contains almost all the sample Foursquare Places API calls.
14
star
29

foursquair

An Adobe AIR desktop client for foursquare
ActionScript
14
star
30

placepicker-sdk-sample

An SDK to help developers add a place picker to their app and also quickly access the Foursquare place that their user is at.
Java
11
star
31

wait

wait gem: executes a block until there's a result
Ruby
10
star
32

hoursparser.js

dumb but useful hours extractor from free-text entry
JavaScript
9
star
33

h3-presto

Presto bindings for H3, a hierarchical hexagonal geospatial indexing system
Java
8
star
34

gitshed

git versioning of large binary files outside the repo.
Python
8
star
35

shapefile-geo

Java
8
star
36

pilgrim-sdk-react-native

React native wrapper for the Pilgrim SDK
Java
7
star
37

fsgo

Reusable libraries for building Go services
Go
7
star
38

FSQMessageForwarder

An Obj-C message forwarder class, for when you don't have access to the source of the sending object.
Objective-C
6
star
39

merchant-app

JavaScript
5
star
40

source_code_analysis

Utilities to analyze, lint and rewrite source code in various languages.
Python
5
star
41

gohfile

5
star
42

exceptionator

MOVED - The project is still under development but this page is deprecated.
JavaScript
5
star
43

foursquare-places

framework agnostic wrapper for foursquare's APIs
JavaScript
5
star
44

android-map-utils

A collection of 3rd party map utility classes
4
star
45

cc-shapefiles

Scala
3
star
46

pilgrim-unity-package

Unity package which enables easy integration with Pilgrim SDK
Objective-C
3
star
47

foursquareapi-csharp

C#
3
star
48

foursquare.github.io

Foursquare open source portal
HTML
2
star
49

movementsdk-ios-spm

Movement SDK for iOS - Swift Package Manager
Swift
2
star
50

foursquare-places-api-samples

Developer Examples for using Foursquare products
HTML
2
star
51

simple-macros

MOVED - The project is still under development but this page is deprecated.
Scala
2
star
52

FSQComponents

Objective-C
2
star
53

RNPilgrimSample

Pilgrim sample app using React Native
Java
2
star
54

json-traverser

Scala
1
star
55

hackmidwest

This repo contains everything developers need to get started at Hack Midwest!
1
star
56

MovementSdk-CocoaPods-Beta

Private CocoaPods Spec repo for the Movement SDK
Ruby
1
star
57

finagle-dual

Support thrift and HTTP on same port with Finagle
Scala
1
star
58

movement-sdk-react-native

React native wrapper for the Movement SDK
Objective-C
1
star
59

pilgrimsdk-adobe-extension

The pilgrim adobe extension
Kotlin
1
star
60

public-model-resources

Jupyter Notebook
1
star
61

mobbing-interview-python

Used by the Security & Quality Team for interviews
1
star
62

RNMovementSample

Movement SDK sample app using React Native
Java
1
star
63

Pilgrim-CocoaPods-Beta

Public cocoapods spec repo for Pilgrim SDK beta builds
Ruby
1
star
64

pilgrim-ios-spm

Pilgrim SDK for iOS - Swift Package Manager
Swift
1
star
65

alertmon

Foursquare's homegrown production alerting platform
Python
1
star
66

commons-old

Temporary duplicate of foursquare/commons (a fork of twitter/commons) while we restructure things.
Java
1
star