IOS UIPageController
【摘要】
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //定义UIScrollView //self.scrollView = [[UI...
-
- (void)viewDidLoad
-
-
{
-
-
[super viewDidLoad];
-
-
// Do any additional setup after loading the view, typically from a nib.
-
-
//定义UIScrollView
-
-
//self.scrollView = [[UIScrollView alloc] init];
-
-
//self.scrollView.frame = CGRectMake(10, 0, 200, 500);
-
-
self.scrollView.contentSize = CGSizeMake(1000,288); //scrollview的滚动范围
-
-
self.scrollView.showsVerticalScrollIndicator = NO;
-
-
self.scrollView.showsHorizontalScrollIndicator = NO;
-
-
//myScrollView.clipsToBounds = YES;
-
-
self.scrollView.delegate = self;
-
-
self.scrollView.scrollEnabled = YES;
-
-
self.scrollView.pagingEnabled = YES; //使用翻页属性
-
-
self.scrollView.bounces = NO;
-
-
-
-
for(int i=0;i<4;i++)
-
-
{
-
-
UIImageView *imageV =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"wel2.png"]];
-
-
[imageV setFrame:CGRectMake(200*i, 0, 192, 288)];
-
-
[self.scrollView addSubview:imageV];
-
-
-
-
}
-
-
-
-
//定义PageControll
-
-
self.pageControl.numberOfPages = 4;//指定页面个数
-
-
self.pageControl.currentPage = 0;//指定pagecontroll的值,默认选中的小白点(第一个)
-
-
[self.pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
-
-
}
-
-
-
-
-
-
-
-
//scrollview的委托方法,当滚动时执行
-
-
- (void)scrollViewDidScroll:(UIScrollView *)sender {
-
-
int page = self.scrollView.contentOffset.x / 192;//通过滚动的偏移量来判断目前页面所对应的小白点
-
-
self.pageControl.currentPage = page;//pagecontroll响应值的变化
-
-
}
-
-
-
-
-
-
- (IBAction)changePage:(id)sender {
-
-
int page = self.pageControl.currentPage;//获取当前pagecontroll的值
-
-
self.label1.text = [[NSString alloc]initWithFormat:@"%d",page];
-
-
[self.scrollView setContentOffset:CGPointMake(200 * page, 0)];//根据pagecontroll的值来改变scrollview的滚动位置,以此切换到指定的页面
-
-
}
文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。
原文链接:zzzili.blog.csdn.net/article/details/8264628
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)