Basic use of ios_21 group purchase _uicollectionview

Source: Internet
Author: User

Tagged with: ipad ios screen Adapter CollectionView

Eventually:



Code snippet:

Deallistcontroller inherited from Uicollectionviewcontroller

Self.view already contains a Uicollectionview

and the data source and proxy are already current controller self

deallistcontroller.m//Handsome _ buy////Created by Beyond on 14-8-14.//Copyright (c) 2014 Com.beyond. All rights reserved.//Click on the dock above the "buy" button corresponding to the controller, above the navigation bar, the right side of the navigation bar is Searchbar, the left side of the navigation bar is a large button (Topmenu) (the interior consists of three small buttons < topmenuitem>) #import "DealListController.h"//The left side of the navigation bar is a large button (top menu) #import "TopMenu.h" #define KITEMW 250#define  KITEMH 250@implementation deallistcontroller//Override Controller Init method-(ID) init{//Create a flow layout uicollectionviewflowlayout *layout    = [[Uicollectionviewflowlayout alloc] init];        Set the flow layout inside each grid width and height, that is, the size of each grid layout.itemsize = Cgsizemake (KITEMW, KITEMH); Call the Initwithcollectionviewlayout method of the parent class Uicollectionviewcontroller, (self is not found here, will go to the parent class to find the method) return [self Initwithcollectionviewlayout:layout];}        -(void) viewdidload{[Super Viewdidload];        1. Basic settings for the top navigation bar [self setnavigationbar]; Basic settings for 2.collectionView [self setcollectionview];}    2. Basic settings of the top navigation bar-(void) setnavigationbar{//1. The search box on the right Uisearchbar *s = [[Uisearchbar alloc] init]; S.frame = CGREctmake (0, 0, 210, 35);    S.placeholder = @ "Please enter product name, address, etc.";        Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:s];    2. Left menu bar Topmenu *top = [[Topmenu alloc] init]; Important, Topmenu inside the item clicked, the created Popmenu will be added to where to go???    is the view Top.controllerview = Self.view of this controller;        Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:top]; }//3.collectionView Basic Settings-(void) setcollectionview{//1. Set the background color of the CollectionView (unlike Tableviewcontroller,        The view of the controller is UIView, added in the UIView collectionview) Self.collectionView.backgroundColor = KGLOBALBG; 2. Important ~ ~ ~ Xib [Self.collectionview registernib:[uinib nibwithnibname:@ "Dealcell" bundle:nil] to be used for registering the cell        forcellwithreuseidentifier:@ "Dealcell"];    3. Set CollectionView to always support vertical scrolling, ready for pull-down refresh (Spring) self.collectionView.alwaysBounceVertical = YES; }//4. Important ~ ~ ~ because when the controller is created, the width default is 768, the high default is 1024, regardless of the screen//only in the Viewwillappear and Viewdidappear methods, you can get the view the most accurate (that is, the actual) Width and height (width and height)-(void) ViewwillappEar: (BOOL) animated{//default calculation layout [self didrotatefrominterfaceorientation:0];} #pragma mark-parent method//intercept, call when screen is about to rotate (Controller monitor screen rotation)-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) Tointerfaceorientation Duration: (nstimeinterval) duration{log (@ "screen is about to be rotated");} Intercept, when screen rotation is complete, call-(void) Didrotatefrominterfaceorientation: (uiinterfaceorientation) frominterfaceorientation{//1. Remove the uicollectionviewflowlayout uicollectionviewflowlayout *layout = (Collectionviewcontroller) that was passed in when creating the            Uicollectionviewflowlayout *) Self.collectionView.collectionViewLayout;    2. Calculate the spacing CGFloat v = 0;    CGFloat h = 0;    CGFloat height = self.view.frame.size.height-44;    CGFloat width = self.view.frame.size.width; if (Uiinterfaceorientationislandscape (self.interfaceorientation)) {//cross-screen spacing v = (height-2 * KItem        H)/3;            H = (width-3 * kitemw)/4;        } else {//vertical screen spacing v = (height-3 * kitemh)/4; H = (Width-2 * kitemw)/3;   }//3. Adjust the distance between the squares of the animation [UIView animatewithduration:4.0 animations:^{//Margin layout.sect in the upper left and right four directions        Ioninset = Uiedgeinsetsmake (V, H, V, h);    The spacing between each line layout.minimumlinespacing = V; }];} #pragma Mark-collectionview Proxy method//Total number of item (that is, Lattice cube)-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (Nsinteger) section{return 6;} Generate each unique lattice-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (    Nsindexpath *) indexpath{static NSString *cellid = @ "Dealcell";        Uicollectionviewcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:cellid ForIndexPath:indexPath]; Set a unique data return cell;}


CollectionView in the general appearance of the same, you can use Xib

Dealcell.xib









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.