Swift creates Uicollectionview

Source: Internet
Author: User

//

Collectionviewcontroller.swift

tab

//

Created by Su on 15/12/8.

Copyright©2015 year Tian. All rights reserved.

//

Import UIKit

Class Collectionviewcontroller:uiviewcontroller, Uicollectionviewdelegate, Uicollectionviewdatasource {

var collectionview:uicollectionview!

Override Func Viewdidload () {

Super.viewdidload ()

Let FlowLayout = Uicollectionviewflowlayout ()

Flowlayout.itemsize = cgsize (width: (Tools). SCREEN_WIDTH-30)/3, Height: (Tools (). SCREEN_WIDTH-30)/3)

CollectionView = Uicollectionview (Frame:self.view.bounds, Collectionviewlayout:flowlayout)

Collectionview.backgroundcolor = Uicolor.whitecolor ()

Collectionview.registernib (uinib (nibname: "Collectionviewcell", Bundle:nil), Forcellwithreuseidentifier: " Collectionviewcell ")

Collectionview.delegate = Self

Collectionview.datasource = Self

Self.view.addSubview (CollectionView)

}

Func CollectionView (Collectionview:uicollectionview, Numberofitemsinsection section:int), Int {

Return 10

}

Func CollectionView (Collectionview:uicollectionview, Cellforitematindexpath Indexpath:nsindexpath) Uicollectionviewcell {

Let cell = Collectionview.dequeuereusablecellwithreuseidentifier ("Collectionviewcell", Forindexpath:indexpath)

return cell

}

Override Func didreceivememorywarning () {

Super.didreceivememorywarning ()

Dispose of any resources the can be recreated.

}

/*

MARK:-Navigation

In a storyboard-based application, you'll often want to do a little preparation before navigation

Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) {

Get The new view controller using Segue.destinationviewcontroller.

Pass the selected object to the new view controller.

}

*/

}

Swift creates Uicollectionview

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.