IOS Uicollectionview-(horizontal scrolling)

Source: Internet
Author: User

#import <UIKit/UIKit.h>@interface appdelegate:uiresponder <UIApplicationDelegate>  *window; @end
#import "AppDelegate.h"#import "RootViewController.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //Override point for customization after application launch.Self.window.backgroundColor =[Uicolor Whitecolor]; Self.window.rootViewController=[[Rootviewcontroller alloc] init];    [Self.window makekeyandvisible]; returnYES;}@end
#import <UIKit/UIKit.h>@interface  rootviewcontroller:uiviewcontroller@end 
#import "RootViewController.h"@interfaceRootviewcontroller () <UICollectionViewDataSource,UICollectionViewDelegate>{}@end StaticNSString *identifier =@"Cell";@implementationRootviewcontroller- (void) viewdidload {[Super viewdidload]; //creating a Layout objectUicollectionviewflowlayout *layout =[[Uicollectionviewflowlayout alloc] init]; //set the direction of scrolling[Layout setscrolldirection:uicollectionviewscrolldirectionhorizontal]; //the gap of the line//layout.minimumlinespacing = 10; //Gap of ColumnLayout.minimuminteritemspacing =Ten; //size of itemLayout.itemsize = Cgsizemake ( -, Max); //Create CollectionViewUicollectionview *collectionview = [[Uicollectionview alloc] Initwithframe:cgrectmake (0, -, [UIScreen Mainscreen].bounds.size.width, Max) Collectionviewlayout:layout]; Collectionview.backgroundcolor=[Uicolor Greencolor]; //Set up proxyCollectionview.datasource =Self ; CollectionView.Delegate=Self ; //tell the system what cell to create in the future (you must register a cell in the system before getting the cell)[CollectionView Registerclass:[uicollectionviewcellclass] Forcellwithreuseidentifier:identifier]; [Self.view Addsubview:collectionview];}//tell the system how many groups there are.-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{return 1;}//tell the system how many lines are in section group-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) section{return  the;}//tells the system Indexpath what the Item line of section group is showing-(uicollectionviewcell*) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{Uicollectionviewcell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath]; Cell.backgroundcolor=[Uicolor Redcolor]; returncell;}- (void) CollectionView: (Uicollectionview *) CollectionView Didselectitematindexpath: (Nsindexpath *) indexpath{NSLog (@"==%lu", Indexpath.row);}@end

IOS Uicollectionview-(horizontal scrolling)

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.