Development environment
MacOS Sierra 10.12, Xcode 8.0, as shown in:
General Ideas
1. Create blank storyboard for rendering list (implemented with Uicollectionview)
2. Customizing the content of a single project (Uicollectionviewcell)
3. Register a single item in the list (Uicollectionview)
4. Register the list to the page (StoryBoard)
5, run to see the effect
1, establish storyboard
This project integrates the Tab bar and Navigation bar, and the entire project (Main.storyboard) tries to look like this:
The list is presented here in the lobby page (Homenavitem Scene) as shown in:
Create Homenavitemcontroller.swift as the background code for the above page, as shown in the top right corner of the Custom Class.
At this point, the interface end of the work is complete.
2. Customize a single cell (Homecollectionviewcell.swift), as shown in the code below:
import UIKit;classHomecollectionviewcell:uicollectionviewcell {varTitle:uilabel?;//the contents of the cell, if you need another control, you can add it yourself OverrideInit (frame:cgrect) {super.init (frame:frame); //register title to celltitle = UILabel (Frame:cgrect (x: -Y:0, Width:UIScreen.main.bounds.width, Height: -)); Title?. TextColor =Uicolor.black; Self.addsubview (Title!); Self.backgroundcolor= Uicolor.blue;//set the entire cell background color, test cell size} required Init?(coder Adecoder:nscoder) {fatalerror ("Cell initialization failed"); }}3. Register the list to the page (Homenavitemcontroller.swift) and, at the same time, register the individual cells with the page, as shown in the following code:
1 import UIKit;2 3 classHomenavitemcontroller:uiviewcontroller, Uicollectionviewdatasource, Uicollectionviewdelegate, uicollectionviewdelegateflowlayout {4 5 varColview:uicollectionview?;//Create a list6 7 //Loading Interface8 Overridefunc viewdidload () {9 super.viewdidload ();Ten OneLet layout =uicollectionviewflowlayout (); A -Colview = Uicollectionview (Frame:CGRect.init (x:0Y:0, Width:UIScreen.main.bounds.width, height:self.view.bounds.height), collectionviewlayout:layout); - theColview?. Register (homecollectionviewcell.self, Forcellwithreuseidentifier:"Colcell") - -Colview?.Delegate=Self ; -Colview?. DataSource =Self ; +Colview?. BackgroundColor =Uicolor.white; - +Layout.itemsize = cgsize (width:375, Height: -); A atSelf.view.addSubview (colview!); - } - - Overridefunc didreceivememorywarning () { - super.didreceivememorywarning (); - } in - //Number of cells toFunc CollectionView (_ Collectionview:uicollectionview, Numberofitemsinsection section:int)Int { + return Ten; - } the * //Cell Specific Content $Func CollectionView (_ Collectionview:uicollectionview, Cellforitemat Indexpath:indexpath)Uicollectionviewcell {Panax NotoginsengLet cell = Collectionview.dequeuereusablecell (withreuseidentifier:"Colcell", for: Indexpath) as!Homecollectionviewcell; -cell.title!. Text ="here is the content: \ (indexpath.row)"; the returncell; + } A}4. Run the viewing effect as shown in:
Finally, to insert a sentence, the entire project is structured as follows:
XCODE8+SWIFT3 Pure Code Mode implementation Uicollectionview