The main objective of this Article is to introduce with you the most basic part of UICollectionView before using it in your Xcode project.
I found this article important to help the developers who are curious to learn some of basics in iOS as a fresher.First of all,you should have some knowledge about View. |
Views are the building blocks for constructing your user interface in iOS.
Read:
Some important notes about View in iPhone.
Some important points About View Controller.
A collection view is basically used to display an ordered collection of data.Simply,It's basically a collection of cells displayed in a grid or according to the properties of custom layout you design.
The behaviour of collection view is similar to table view.Similar to table view,custom data source object supplies data to collection view and collection view displays it using cell ,layout and supplementary views.
The delegate of UICollectionView acts on behalf of Collection View in response to user interactions and so on.
Note:
UICollectionView is the subclass of UIScrollView.
1)It supports custom layout
2)One of the best things of collection view is the separation between the data and the presentation layers,that depends upon a separate object to handle the layout.
3)You can design and view a catalog of items with variable sizes, optionally sorted into multiple sections
4)You can add,rearrange and edit a collection of items in collection view.
5)You can choose from a frequently changing display of items in collection view.
What is layout in collection view ?
1)The layout of collection view decides the placement and visual attributes of the views.
2)UIKit provides a layout that consists of a basic grid layout with some customisations.
Note:
You can use your own custom layouts to make the views flexible as per your own requirement.
Layout objects are subclasses of UICollectionViewLayout.
Apple provides you the default flow layout to use.
Some major components of UICollectionView:
1.Cell:
Cell of collection view is similar to the table view.The cells are the main elements that make up the content of the view are added as the subviews to Collection View.Cells are arranged in grid like structure,can be created programmatically or by interface builder.
You can customise the background of a cell as shown below which is presented as BackgroundView.
It's rendered just below the selected SelectedBackgroundView.
SelectedBackgroundView :
It supports for selection.As displayed a preview below indicates the cell is selected. It is rendered just below the ContentView when a cell is selected.
ContentView :
ContentView holds the content that the cell presents. It is rendered in the topmost z-order on the screen.
You can display some extra information not within the cells somewhere within the collection view,you need to make use of supplementary views.
For example:
You can use them for header and footer customisation.
It's an another part of collection view.If you want to enhance the visual appearance of the collection view ,you can use decoration views.
Example:
Adding a background image to collection view is a good example of decoration view.
Let me explain some behaviours a Collection View supports.
For example:
1)Users can elect one or more items from Collection View.
2)Users can Insert, delete, and reorder items or sections.
3)Users can edit an itemBy default, the delegates of collection view can detect when the user taps a specific cell and it updates the cell’s selected or highlighted properties as appropriate. You can write code that configures a collection view to support multiple-item selection or that draws the selected or highlighted states yourself.
I have just shared some basic concept about UICollection View.I will come with more tutorials and sample codes about collection view in Objective C and as well as swift.If you find any difficulties understanding the above article or if you need any assistance ,feel free to put a comment :)
Read More Posts:
What Are The Main Responsibilities Of A View Controller ?
Explain The Difference Between loadView() And viewDidLoad() in iOS
How To Explain UIViewController Life Cycle in iOS ?