UIScrollView和UIPageControl的配合使用 - iOS - UI基础知识总结11
来源:互联网 发布:mac可以玩什么国内网游 编辑:程序博客网 时间:2024/05/20 20:55
注意:MRC模式
在.h中声明两个属性
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController@property (nonatomic, retain) UIScrollView *myScrollView;@property (nonatomic, retain) UIPageControl *myPageControl;@end
释放
- (void)dealloc{ [_myScrollView release]; [_myPageControl release]; [super dealloc];}
在viewDidLoad中创建UIScrollView对象和UIPageControl对象
添加一个宏定义#define kPageControlHeight 50
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor grayColor]; self.myScrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; self.myScrollView.backgroundColor = [UIColor grayColor]; [self.view addSubview:self.myScrollView]; [self.myScrollView release]; // 给scrollView加图片 for (int i = 0; i < 6; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]]; UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)]; imageView.image = image; [self.myScrollView addSubview:imageView]; [imageView release]; } // 给scrollView设置contentSize self.myScrollView.contentSize = CGSizeMake(6*self.view.frame.size.width, self.view.frame.size.height); // 整页翻动(一页一页翻动) self.myScrollView.pagingEnabled = YES; // 给scrollView添加代理对象 self.myScrollView.delegate = self; // 创建UIPageControl self.myPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - kPageControlHeight, self.view.frame.size.width, kPageControlHeight)]; // 设置页数 self.myPageControl.numberOfPages = 6; // 设置当前选中的点的颜色 self.myPageControl.currentPageIndicatorTintColor = [UIColor redColor]; // 设置未被选中的点的颜色 self.myPageControl.pageIndicatorTintColor = [UIColor cyanColor]; [self.view addSubview:self.myPageControl]; [self.myPageControl release]; // 给pageControl设置点击事件 [self.myPageControl addTarget:self action:@selector(myPageControlAction:) forControlEvents:UIControlEventValueChanged];}
#pragma mark - UIScrollView Delegate// scrollView的代理方法// 滑动减速完成- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSLog(@"减速完成"); // 滑动一次结束时让pageControl的点跳动 // 先找到偏移量,再根据偏移量设置currentPage self.myPageControl.currentPage = self.myScrollView.contentOffset.x / self.view.frame.size.width;}- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"正在滑动");}- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ NSLog(@"开始减速");}- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{ NSLog(@"将要结束拖拽");}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ NSLog(@"已经结束拖拽");}- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{ NSLog(@"已经完成缩放");}
#pragma mark - pageControl 点击事件处理- (void)myPageControlAction:(UIPageControl *)sender{ self.myScrollView.contentOffset = CGPointMake(sender.currentPage * self.view.frame.size.width, 0);}
0 0
- UIScrollView和UIPageControl的配合使用 - iOS - UI基础知识总结11
- IOS--UIScrollView和UIPageControl配合使用
- iOS--UIScrollView和UIPageControl配合使用完成引用介绍页面
- UI UIScrollView和UIPageControl的结合使用
- iOS UIPageControl与UIScrollView配合使用代码
- UI基础知识 -- UIScrollView UIPageControl
- iOS UIScrollView 和 UIPageControl的简单使用
- iOS中UIScrollView和UIPageControl的使用
- iOS --- UIScrollView和UIPageControl的简单使用
- IOS UI UIScrollView+UIPageControl组合使用
- UI - UIScrollView和UIPageControl
- UIScrollView和UIPageControl配合使用完成引用介绍页面
- iOS中UIScrollView和UIPageControl以及NSTimer的综合使用
- UIPageControl的详细使用 (与uiscrollview配合使用)
- UIScrollView UIPageControl 的使用
- UIScrollView UIPageControl 的使用
- UIScrollView + UIPageControl的使用
- UIScrollView&UIPageControl的使用
- [Linux] git send-email的使用
- 使用maven搭建ssh框架静态资源路径
- Yii学习笔记之三(在windows 上安装 advanced )
- 20150609构造方法和self指针
- screenX clientX pageX的区别
- UIScrollView和UIPageControl的配合使用 - iOS - UI基础知识总结11
- 第四部分 开发工具及测试工具-内容来自互联网
- mpstat 命令详解
- L1范式和L2范式
- 名词从句的作用
- #298 (div.2) A. Exam
- Unity教程之手把手教你Animator状态机如何切换状态
- hiho第一周——最长回文子串
- 黑马程序员---集合-泛型、增强for、Set集合