Uiscrollview Picture page display, here to use the Uipagecontrol

Source: Internet
Author: User

#import "MJViewController.h"

#define KCOUNT 8//definition macros, frequently used in programs, easy to expand

@interface Mjviewcontroller () <UIScrollViewDelegate>

{

Uipagecontrol *_pagecontrol;

}

@end

@implementation Mjviewcontroller

-(void) viewdidload

{

[Super Viewdidload];

CGFloat w = self.view.frame.size.width;

CGFloat h = self.view.frame.size.height;

for (int i = 0; i< kcount; i++) {

Uiimageview *imageview = [[Uiimageview alloc] init];

1. Set the frame

Imageview.frame = CGRectMake (i * w, 0, W, h);

2. Setting up a picture

NSString *imgname = [NSString stringwithformat:@ "0%d.jpg", i + 1];

Imageview.image = [UIImage imagenamed:imgname];

[_scrollview Addsubview:imageview];

}

Height = = 0 means no vertical scrolling

_scrollview.contentsize = Cgsizemake (kcount * w, 0);

_scrollview.showshorizontalscrollindicator = NO;

_scrollview.pagingenabled = YES;

_scrollview.delegate = self;

Add Pagecontrol

Uipagecontrol *pagecontrol = [[Uipagecontrol alloc] init];

Pagecontrol.center = Cgpointmake (w * 0.5, h-20);

Pagecontrol.bounds = CGRectMake (0, 0, 150, 50);

Pagecontrol.numberofpages = Kcount; show how many dots (how many pages)

Set the dot color of a non-selected page

Pagecontrol.pageindicatortintcolor = [Uicolor Redcolor];

Set the dot color of the selected page

Pagecontrol.currentpageindicatortintcolor = [Uicolor Bluecolor];

Disable the default click function

pagecontrol.enabled = NO;

[Self.view Addsubview:pagecontrol];

_pagecontrol = Pagecontrol;

}

Proxy methods for #pragma mark-uiscrollview

#pragma mark calls when ScrollView is rolling.

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView

{

int page = Scrollview.contentoffset.x/scrollview.frame.size.width;

NSLog (@ "%d", page);

Set Page numbers

_pagecontrol.currentpage = page;

}

@end

Uiscrollview Picture page display, here to use the Uipagecontrol

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.