#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)