UIScrollView
2016-01-07 11:14
417 查看
// // RootViewController.m // Lesson06UIScrollView // // Created by lanouhn on 16/1/7. // Copyright (c) 2016年 lanouhn. All rights reserved. // #import "RootViewController.h" @interface RootViewController () { UIScrollView *scrollView; } @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor brownColor]; //UIScrollView, 继承于UIView, 滚动视图, 用于展示超出一个屏幕的内容. //frame: 可视区域的大小和位置 // scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds]; scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; scrollView.backgroundColor = [UIColor orangeColor]; //内容页的大小, 内容页的大小必须超过可视区域的大小才可以滚动,能够装下要放的内容 scrollView.contentSize = CGSizeMake(1000, 1000); //是否显示水平滚动条 scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; //是否支持回弹 scrollView.bounces = YES; //是否关闭滚动效果 scrollView.scrollEnabled = YES; //点击状态栏滚到顶部 scrollView.scrollsToTop = YES; //内容页的偏移量 scrollView.contentOffset = CGPointMake(0, 100); [self.view addSubview:scrollView]; [scrollView release]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(23, 0, 329, 924)];//图片除2, 对称放置 imageView.image = [UIImage imageNamed:@"11.jpg"]; //视图必须放到scrollView [scrollView addSubview:imageView]; [imageView release]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(320, 600, 50, 50); //圆角半径 button.layer.cornerRadius = 25; //描边宽度 button.layer.borderWidth = 1; //描边颜色 button.layer.borderColor = [UIColor yellowColor].CGColor; [button setTitle:@"顶部" forState:UIControlStateNormal];//正常状态 //button 关联方法 [button addTarget:self action:@selector(top) forControlEvents:UIControlEventTouchUpInside];//按下之后松手 [self.view addSubview:button]; [button release]; } - (void)top { //1. // scrollView.contentOffset = CGPointZero; //2.有个缓慢的过程 [scrollView setContentOffset:CGPointZero animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ //在建一个视图 // // ShowViewController.m // Lesson06UIScrollView // // Created by lanouhn on 16/1/7. // Copyright (c) 2016年 lanouhn. All rights reserved. // #import "ShowViewController.h" @interface ShowViewController () @end @implementation ShowViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //可视图的大小 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; //内容可以放下所 scrollView.contentSize = CGSizeMake(375 * 4, 667); //是否整屏滑动 scrollView.pagingEnabled = YES; [self.view addSubview:scrollView]; [scrollView release]; for (NSInteger i = 0; i < 4; i++) { //图片视图可以很好的放下图片(为了保证图片. 计算一下宽高) UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(375 * i, 0, 375, 667)]; NSString *name = [NSString stringWithFormat:@"%ld.jpg", i + 1]; imageView.image = [UIImage imageNamed:name]; [scrollView addSubview:imageView]; [imageView release]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end @end
相关文章推荐
- iOS UIView 及其子类添加阴影(shadowColor,shadowOffset,shadowOpacity)
- iOS:UICollectionView的构建及使用
- UICollectionView的简单使用
- 1Z0-050 question 1
- UITableView实现上拉加载更多
- 简单实用Handler传递数据并且更新UI界面
- easyUI自定义DataGrid分页栏
- AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
- Hibernate继承映射的“Could not format discriminator value to SQL string”错误解决方法
- 1.UIButton的基本使用
- EasyUi心得
- Understanding Steering Behaviors: Queue
- 构建一个倒排索引 A first take at building an inverted index
- UITableView中刷新单行cell与单个section段的方法
- UIAlertView、 UIActionSheet
- 拖动条控件 (UISlider)
- 进度环控件 (UIActivityIndicatorView)
- 进度条控件 (UIProgressView)
- 图像控件 (UIImageView)
- UE4 Socket多线程非阻塞通信【2】