iOS development-new feature interface (Uicollectionview)

Source: Internet
Author: User

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)

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.