Ios_8_scrollview Sub-page

Source: Internet
Author: User

Eventually:



BeyondViewController.h

  beyondviewcontroller.h//  8_scrollview pagination Browse////  Created by Beyond on 14-7-25.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller@property (Weak, nonatomic) Iboutlet Uiscrollview *scrollview; @end



BeyondViewCon TROLLER.M

beyondviewcontroller.m//8_scrollview Page View/* The following code has performance issues, only as a new feature introduction interface using not as a picture browser ~ 1, one-time generation of 8 ImageView there will be performance problems, the solution Method: Use 3 ImageView (or 2 ImageView) 2, in addition, loop playback has not implemented *///Created by beyond on 14-7-25.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h"//Picture Total number # define Kimgcount 8@interface Beyondviewcontroller () <uiscrollviewdelegate>{//Pagination bar code indicator Controller Uipagecontrol *_pagecontrol;} @end @implementation beyondviewcontroller-(void) viewdidload{[Super viewdidload];//Call custom method [self scrollviewwithpage ];} scrollview-with paging function (void) scrollviewwithpage{//1, setting the visual size of the ScrollView, content size, etc properties _scrollview.frame = Self.view.bou    Nds    _scrollview.showshorizontalscrollindicator = NO;    _scrollview.showsverticalscrollindicator = NO;    _scrollview.bounceszoom = NO;    _scrollview.bounces = NO;        Set the code to listen for the scrolled event _scrollview.delegate = self; 2, create 8 Uiimageview, add to ScrollView//each picture is wide, high cgfloat IMGW = self.view.bounds.size.Width    CGFloat imgh = self.view.bounds.size.height; for (int i=0; i<kimgcount; i++) {//Uiimageview//Picture name: 01.jpg ~ 07.jpg nsstring *imgname = [nsstr        ing stringwithformat:@ "0%d.png", i+1];        Uiimageview *imgview = [[Uiimageview alloc]initwithimage:[uiimage Imagenamed:imgname]];        If the image inside the ImageView is not deformed//set the following two properties of the Uiimageview object, the picture can be filled without deforming and filling the picture frame as a precondition.        Imgview.clipstobounds = YES;        Imgview.contentmode = Uiviewcontentmodescaleaspectfill;       Y is a 0,x is a attached imgview.frame = CGRectMake (I*IMGW, 0, IMGW, IMGH);    Add all the pictures to ScrollView [_scrollview Addsubview:imgview];    }//3, the most important, is the scrolling area//_scrollview.contentsize = Cgsizemake (KIMGCOUNT*IMGW, IMGH);    0 stands for Height direction not scrolling _scrollview.contentsize = Cgsizemake (KIMGCOUNT*IMGW, 0);            Press ScrollView the width of the page _scrollview.pagingenabled = YES;    4,pagecontrol Paging Indicator Bar _pagecontrol = [[Uipagecontrol alloc]init]; Pagecontrol The center point of the pagination indicator bar in the middle of the bottom _Pagecontrol.numberofpages = Kimgcount;    This most important _pagecontrol.center = Cgpointmake (imgw*0.5, imgH-20);    _pagecontrol.bounds = CGRectMake (0, 0, 150, 15);    _pagecontrol.pageindicatortintcolor = [Uicolor Graycolor];    _pagecontrol.currentpageindicatortintcolor = [Uicolor Redcolor]; _pagecontrol.enabled = NO;    Cancels its default click behavior [Self.view Addsubview:_pagecontrol]; }/* in this method, can be performance optimization, because constantly in the monitoring of scrolling, so at any time to do 3 uiimageview splicing, or even reduced to only 2 Uiimageview for dynamic splicing */-(void) Scrollviewdidscroll: ( Uiscrollview *) scrollview{//ScrollView Contentoffset is the most important attribute, the point, X, y record is the distance of the scroll, relative to the ScrollView visual interface of the upper left corner of the distance cgpoint off    set = Scrollview.contentoffset;    int Curpageno = offset.x/_scrollview.bounds.size.width;    _pagecontrol.currentpage = Curpageno; } @end








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.