Xcode7.2:用UIScrollView实现应用新特性(欢迎页)
来源:互联网 发布:卡通农场mac版 编辑:程序博客网 时间:2024/05/01 02:43
// Created by djb on 15/12/22.// Copyright © 2015年 bao. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UIScrollViewDelegate, UIPageViewControllerDelegate>@property (nonatomic, strong) UIScrollView *scrollView;@property (nonatomic, strong) UIPageControl *pageControls;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [self configUI];}-(void)configUI { UIScrollView *scroll = [[UIScrollView alloc] init]; scroll.delegate = self; scroll.frame = self.view.bounds; scroll.backgroundColor = [UIColor greenColor]; scroll.contentSize = CGSizeMake(4 * scroll.bounds.size.width, 0); scroll.showsHorizontalScrollIndicator = NO; scroll.bounces = NO; for (int i = 0; i<4; i++) { UIView *subView = [[UIView alloc] initWithFrame:self.view.bounds]; subView.backgroundColor = [UIColor yellowColor]; subView.bounds = scroll.bounds; subView.frame = CGRectMake(i * subView.bounds.size.width, 0, scroll.bounds.size.width, scroll.bounds.size.height); subView.layer.borderWidth = 20; subView.layer.borderColor = [UIColor redColor].CGColor; UILabel * lbl = [[UILabel alloc] init]; lbl.frame = CGRectMake(50, 150, 100, 50); lbl.text = [NSString stringWithFormat:@"第%d张", i+1]; lbl.backgroundColor = [UIColor whiteColor]; [subView addSubview:lbl]; scroll.pagingEnabled = YES; [scroll addSubview:subView]; } [self.view addSubview:scroll]; UIPageControl *pageControl = [[UIPageControl alloc] init]; self.pageControls = pageControl; pageControl.numberOfPages = 4; pageControl.center = CGPointMake(scroll.center.x, scroll.frame.size.height * 0.9); pageControl.pageIndicatorTintColor = [UIColor greenColor]; pageControl.currentPageIndicatorTintColor = [UIColor brownColor]; [self.view addSubview:pageControl]; }-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"%@", NSStringFromCGPoint(scrollView.contentOffset)); int page = (scrollView.contentOffset.x / scrollView.bounds.size.width) + 0.5; self.pageControls.currentPage = page; }
效果如图:
0 0
- Xcode7.2:用UIScrollView实现应用新特性(欢迎页)
- IOS判断应用是否第一次打开&UIScrollView实现新应用第一打开欢迎介绍页面
- Xcode7新特性
- XCode7 新特性 Bitcode
- iOS-xcode7 新特性相关
- Xcode7新特性之bitcode
- UINavigationController 和 UIScrollView新特性
- Xcode7 &&iOS9一些新特性 记录
- Xcode7 collectionView的编辑新特性
- 用uiscrollview制作欢迎引导页
- xcode7.0新特性之一:真机调试免证书
- xcode7.0-iOS9新特性之二:网络适配
- xcode7.0-iOS9新特性之三:watch
- 【IOS-DEMO】UIScrollView+UIPageControl 实现欢迎页面
- HTML5新特性结合PHP实现多图片格式转换功能 欢迎讨论
- win8商店应用新特性
- 应用"新特性"功能demo
- iOS应用新特性界面
- poj 2536 Gopher II 最大匹配
- Mysql之如何建立索引以及组合索引
- ios 编译第三方库
- IOS网络图片缓存详解
- 训练深度模型的优化问题(一)
- Xcode7.2:用UIScrollView实现应用新特性(欢迎页)
- memcahed
- Redis与Memcached的区别
- C语言中强制数据类型转换的总结
- 二叉树的遍历
- Java 中的三目运算符
- this
- Eclipse RCP - 第一个RCP程序
- 《弟子规》全集译文,为孩子的明天存下来!