iOS UIPageControl简单实例
来源:互联网 发布:小区网络监控设计方案 编辑:程序博客网 时间:2024/06/04 18:34
iOS UIPageControl简单范例
关于自动 滚动代码 有待补充
实例中的图片自行添加
.h 文件代码
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIScrollViewDelegate>{ UIScrollView *_scrollView; NSMutableArray *slideImages; UIPageControl *_page;}@end
.m 文件代码
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 240)]; _scrollView.bounces = NO; _scrollView.pagingEnabled = YES; _scrollView.delegate = self; _scrollView.contentOffset = CGPointMake(320, 0); _scrollView.contentSize = CGSizeMake(1920,240); _scrollView.showsVerticalScrollIndicator =NO; _scrollView.showsHorizontalScrollIndicator = NO; _scrollView.userInteractionEnabled = YES; [self.view addSubview:_scrollView]; slideImages = [[NSMutableArray alloc]initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png", nil]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:([slideImages count]-1)]]]; imageView.frame = CGRectMake(0, 0, 320, 240); [_scrollView addSubview:imageView]; for (int i = 0;i<[slideImages count];i++) { //loop this bit UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:i]]]; imageView.frame = CGRectMake(320*i+320, 0, 320, 240); imageView.userInteractionEnabled = YES; [_scrollView addSubview:imageView]; } imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:0]]]; imageView.frame = CGRectMake(320*5, 0, 320, 240); [_scrollView addSubview:imageView]; _page = [[UIPageControl alloc]initWithFrame:CGRectMake(240, 230, 70, 30)]; _page.numberOfPages = 4; _page.currentPage = 0; // _page.backgroundColor = [UIColor grayColor]; [_page addTarget:self action:@selector(pageAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_page]; // Do any additional setup after loading the view. }- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ int currentPage = (_scrollView.contentOffset.x - _scrollView.frame.size.width / ([slideImages count]+2)) / _scrollView.frame.size.width + 1; NSLog(@"%d",currentPage); if (currentPage==0) { [_scrollView scrollRectToVisible:CGRectMake(320*4, 0, 320, 240) animated:NO]; } else if (currentPage==([slideImages count]+1)) { //如果是最后+1,也就是要开始循环的第一个 [_scrollView scrollRectToVisible:CGRectMake(320, 0, 320, 240) animated:NO]; }}- (void)scrollViewDidScroll:(UIScrollView *)sender{ int page = _scrollView.contentOffset.x/320-1; _page.currentPage = page;}-(void)pageAction{ int page = _page.currentPage; [_scrollView setContentOffset:CGPointMake(320 * (page+1), 0)];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }@end
0 0
- iOS UIPageControl简单实例
- IOS 滚动页面UIPageControl实例
- iOS UIPageControl的简单使用
- iOS UIScrollView 和 UIPageControl的简单使用
- iOS --- UIScrollView和UIPageControl的简单使用
- ios--UIPageControl
- iOS UIPageControl
- [iOS]UIScrollView 与 UIPageControl实现简单相册功能
- UIPageControl的简单应用
- UIPageControl的简单使用
- UIPageControl的简单使用
- ios:详解UIPageControl
- iOS UIPageControl使用
- iOS UIPageControl使用
- IOS初级:UIScrollView & UIPageControl
- iOS开发 -- UIpageControl
- iOS开发 ----- UIScrollview UIPageControl
- iOS编程-------UIScrollView / UIPageControl
- [LeetCode] Validate Binary Search Tree
- 变参数print函数的实现va_list
- Android的ContentProvider(一)
- nginx按天分割日志
- android:屏幕自适应
- iOS UIPageControl简单实例
- ORACLE配置tnsnames.ora文件实例
- Unity爆炸检测
- linux中用wine加载使用TortoiseSVN
- 【ural】1960. Palindromes and Super Abilities【Palindromic Tree】
- Android APK反编译就这么简单 详解(附图)
- Java 从Jar文件中动态加载类
- OpenNI+VS2010环境配置
- 最简单的基于librtmp的示例:发布H.264(H.264通过RTMP发布)