UIScroll和UIPickView
- .h
#import <UIKit/UIKit.h>
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface ViewController : UIViewController<UIScrollViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource>
/**
* 滚动视图
*/
@property (nonatomic, strong)UIScrollView *scroll;
/**
* 分页控件
*/
@property (nonatomic, strong)UIPageControl *page;
/**
* 滚动条
*/
@property (nonatomic, strong)UIPickerView *pick;
// 数据源
@property (nonatomic, strong)NSArray *arr_data;
@end
- .m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
self.scroll.backgroundColor = [UIColor grayColor];
self.scroll.contentSize = CGSizeMake(WIDTH*3, HEIGHT);
// 分页
self.scroll.pagingEnabled = YES;
// 隐藏滚动条
self.scroll.showsHorizontalScrollIndicator = NO;
UIImageView *imv1 = [[UIImageView alloc] initWithFrame:self.view.frame];
imv1.backgroundColor = [UIColor purpleColor];
UIImageView *imv2 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];
imv2.backgroundColor = [UIColor blueColor];
UIImageView *imv3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT)];
imv3.backgroundColor = [UIColor redColor];
[self.scroll addSubview:imv1];
[self.scroll addSubview:imv2];
[self.scroll addSubview:imv3];
[self.view addSubview:self.scroll];
// 分页标识
self.page = [[UIPageControl alloc] initWithFrame:CGRectMake((WIDTH-120)/2, HEIGHT-100, 120, 30)];
self.page.numberOfPages = 3;
self.page.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.page];
// 代理
self.scroll.delegate = self;
// 滚动条
self.arr_data = @[@"年", @"月", @"日", @"时", @"分", @"秒"];
self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake((WIDTH-200)/2, HEIGHT-300, 200, 100)];
// 两个代理(代理和数据源)
self.pick.delegate = self;
self.pick.dataSource = self;
[self.view addSubview:self.pick];
}
// 分页
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.page.currentPage = (int)scrollView.contentOffset.x/WIDTH;
}
// 代理
#pragma mark - delegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
#pragma mark - sourcedata
// 数据源
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return self.arr_data.count;
}
#pragma mark - title
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return self.arr_data[row];
}
#pragma mark - selecter
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// row:下标
NSLog(@"%@", self.arr_data[row]);
}
#pragma mark - rowheight
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 50;
}
UIScroll和UIPickView的更多相关文章
- UIPickView 和 UIDatePicker
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- iphone/ipad关于size, frame and bounds总结和UIScroll view学习笔记
1. iphone/ipad大小 Device Screen dimensions(in points) iphone and ipod 320 X 480 ipad 768 X 1024 2. UI ...
- UIPickView的简单介绍
UIPickView的简单介绍 设置UIPickView的时候,我们主要需要设置一下下面的两个属性 UIPickerView *pickView1; pickView1 = [[UIPickerVie ...
- IOS UIPickView+sqlite 选择中国全部城市案例
1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...
- UIPickView的简单使用
好记性不如烂笔头,勤做笔记. 摘要: 1.UIPickVIew 几个重要的属性 (1)datePickerMode UIDatePickerModeTime, // Displays hour, mi ...
- UIPickView的基本使用
UIPickView和TableView一样,想要展示数据也要设置数据源和代理设置数据源self.pickView.dataSource = self;设置代理self.pickView.delega ...
- UIPickView之自定义生日键盘和城市键盘
//// ViewController.m// 04-键盘处理// // #import "ViewController.h"#import "XMGProvince ...
- 自定义UIPickView
效果图 源码 https://github.com/YouXianMing/Animations 说明 1. 数据适配器PickerViewDataAdapter含有PickerViewCompone ...
- ios之UIPickView
以下为控制器代码,主要用到的是UIPickerView 主要步骤:新建一个Single View Application 然后,如上图所示,拖进去一个UILabel Title设置为导航,再拖进去一个 ...
随机推荐
- 转 Oracle12c/11个 Client安装出现"[INS-30131]"错误“请确保当前用户具有访问临时位置所需的权限”解决办法之完整版
错误分析:安装时exe会自动解压到C:\Users\Administrator\AppData\Local\Temp再进行安装,当文件夹权限不足时就会拒绝安装程序的访问: 第一步: 在win+R输入 ...
- 关于tag,viewWithTag
iOS SDK内置了一套搜寻机制,可通过tag来查找子视图. **苹果公司很少给子视图设置tag.笔者所知范围的唯一例外出现在UIAlertView中,该类会给按钮分别设置值为1.2的标签 viewW ...
- pipe的实现
本文进行了详细的描述,http://blog.csdn.net/zhouhong1026/article/details/8151235
- easyui实现权限管理
在js中: function makeEasyTree(data){ if(!data) return []; var _newData = []; //最终返回结果 var _treeArray = ...
- mysql问题总结,远程登录
http://blog.sina.com.cn/s/blog_4550f3ca0101axzd.html 更改mysql数据库的数据库名 http://tech.sina.com.cn/s/s/200 ...
- GameUnity 2.0 文档(一) 事件机制
新版本和旧版本一样,有socket事件和内部事件.区别在于,你只要一个监听就可以 消息协议规则: 用类名标记协议的好处是什么? 是利用反射机制来处理每个消息. 程序启动的时候,会读取所有类名,并字典保 ...
- GameUnity 2.0 发布倒计时
万众期待的 gameunity 网络游戏框架 已经完成了,现在在最后的检验调试阶段. 因为版本 改动非常之大,所以 版本号 从0.2版本 改成 2.0版本. gameunity事件部分,一如既往保持高 ...
- Job 逻辑执行图
General logical plan 典型的 Job 逻辑执行图如上所示,经过下面四个步骤可以得到最终执行结果: 从数据源(可以是本地 file,内存数据结构, HDFS,HBase 等)读取数据 ...
- hdu_2222_Keywords Search(AC自动机板子)
题目连接:hdu_2222_Keywords Search 存个自己写的AC自动机 #include<cstdio> #include<cstring> #define F(i ...
- JSON缺包导致的错误
Json-lib 需要的 jar 包 commons-beanutils-1.8.3.jar commons-collections-3.2.1.jar commons-lang-2.6.jar co ...