No app in just download or update, the app has some features need to pass to the user, this time we will use a new interface, the user just opened the software can see a variety of display pictures, left and right sliding can also switch pictures, then the new feature interface is how to achieve it, Below I use the introduction under how code to implement the sexual interface, using iOS uicollectionview, custom cell to achieve.
In CollectionViewCell.h
#import <UIKit/UIKit.h>@interface*image; @end
In COLLECTIONVIEWCELL.M
#import "CollectionViewCell.h"@interfaceCollectionviewcell () @property (nonatomic,weak) Uiimageview*ImageView;@end@implementationCollectionviewcell//set the location of child controls-(void) layoutsubviews{[Super Layoutsubviews]; Self.imageView.frame=self.bounds;}//Lazy Loading-(Uiimageview *) imageview{if(_imageview = =Nil) {Uiimageview*imageview =[[Uiimageview alloc] init]; _imageview=ImageView; [Self.contentview Addsubview:_imageview]; } return_imageview;}-(void) SetImage: (UIImage *) image{_image=image; Self.imageView.image=_image;}@end
In COLLECTIONVIEWCONTROLLER.M
#import "CollectionViewController.h"#import "CollectionViewCell.h"@interfaceCollectionviewcontroller () @property (nonatomic,weak) Uipagecontrol*Pagecontrol;@end@implementationCollectionviewcontrollerStaticNSString *ConstReuseidentifier =@"Cell";-(instancetype) init{uicollectionviewflowlayout*layout =[[Uicollectionviewflowlayout alloc] init]; //set the cell sizeLayout.itemsize =[UIScreen mainscreen].bounds.size; //Set Line spacingLayout.minimumlinespacing =0; //Set Scroll DirectionLayout.scrolldirection =Uicollectionviewscrolldirectionhorizontal; return[Super Initwithcollectionviewlayout:layout]; }//using Uicollectionviewcontroller//1. Setting layout parameters when initializing//2. You must collectionview to register the cell//3. Custom cell- (void) viewdidload {[Super viewdidload]; //Register Cell[Self.collectionview Registerclass:[collectionviewcellclass] Forcellwithreuseidentifier:reuseidentifier]; Self.collectionView.pagingEnabled=YES; Self.collectionView.bounces=NO; Self.collectionView.showsHorizontalScrollIndicator=NO; //Add PagecontrollerUipagecontrol *pagecontrol =[[Uipagecontrol alloc] init]; Pagecontrol.numberofpages=3; Pagecontrol.pageindicatortintcolor=[Uicolor Blackcolor]; Pagecontrol.currentpageindicatortintcolor=[Uicolor Bluecolor]; Pagecontrol.center= Cgpointmake (self.view.frame.size.width*0.5, self.view.frame.size.height- -); Self.pagecontrol=Pagecontrol; [Self.view AddSubview:self.pageControl];}//scrolling will call-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{//Gets the current offset, calculating the current page number intNumber = scrollview.contentoffset.x/scrollview.bounds.size.width+0.5; Self.pageControl.currentPage=Number ;}#pragmaMark <uicollectionviewdatasource>-(Nsinteger) Numberofsectionsincollectionview: (UICollectionView *) CollectionView {return 1;}-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) Section {return 3;}-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) Indexpath {Collectionviewcell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:reuseidentifier Forindexpath:indexpath]; Cell.image= [UIImage imagenamed:@"Cloud"]; returncell;}
Run the code, the final effect is as follows, left and right can slide, the bottom point is the first page.
iOS development-new feature interface (Uicollectionview)