IOS Uiscrollview,uipagecontrol

Source: Internet
Author: User

Uiscrollview can be used to display more than one screen of content, beyond the scope of the screen can be viewed by swiping, the Uipagecontrol class provides a line of points to indicate which page of a multi-page view is currently displayed.

The following implements a simple picture of an auto player as an example of some of the methods in Uiscrollview and Uipagecontrol classes.

Note: Scrolly,kscreenwidth,kscreenheight,kimgcount in the code below are defined constants

#define kScreenHeight [UIScreen mainScreen].bounds.size.height#define kScreenWidth [UIScreen mainScreen].bounds.size.widthCGFloat10;CGFloat10;CGFloat200;

Size in frame refers to the visual range of the Uiscrollview

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, scrollY, kScreenWidth, kScreenHeight - scrollY)];

Set the scrolling range (size) of the Uiscrollview

self.scrollView.contentSize = CGSizeMake(kScreenWidth * kImgCount, kScreenHeight - scrollY);

Control the full page Flip (page effect) of a control

self.scrollView.pagingEnabledYES;

Uiscrollview the current scrolling position, animated:yes means scrolling at a constant speed

[self.scrollView setContentOffset:point animated:YES];

For example: When you drag to half, the number of pages is 1.

NSInteger page = scrollView.contentOffset.x0.5;//contentOffset.x 表示在x轴上拖动的距离    self.pageCtrl.currentPage = page;

Initialize Uipagecontrol

self.pageCtrl = [[UIPageControl alloc] initWithFrame:CGRectMake((kScreenWidth - pageCtrlWidth)/2, kScreenHeight - scrollY, kScreenWidth/2, scrollY/2 )];

How many dots are shown in total?

self.pageCtrl.numberOfPages = kImgCount;

Set the dot color of a non-selected page

self.pageCtrl.pageIndicatorTintColor = [UIColor greenColor];

Set the dot color of the selected page

self.pageCtrl.currentPageIndicatorTintColor = [UIColor yellowColor];

a Insertsubview b abovesubview:c is to insert B into a and on top of a already existing child view C
a Addsubview B is to cover B directly at the top of a
a Insertsubview b atindex:2 is the position where B is inserted into the sub-view of a, index 2 (bottom 0)
A Insertsubview b belowsubview:c is to insert B into a and under a already existing sub-view C

Cases:

[selfinsertSubview:selfaboveSubview:self.scrollView];

Temporarily update Uiscrollview and Uipagecontrol These methods, of course, there are some other methods are not organized, follow-up will continue to accumulate according to learning situation!

IOS Uiscrollview,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.