• .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的更多相关文章

  1. UIPickView 和 UIDatePicker

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  2. 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 ...

  3. UIPickView的简单介绍

    UIPickView的简单介绍 设置UIPickView的时候,我们主要需要设置一下下面的两个属性 UIPickerView *pickView1; pickView1 = [[UIPickerVie ...

  4. IOS UIPickView+sqlite 选择中国全部城市案例

    1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...

  5. UIPickView的简单使用

    好记性不如烂笔头,勤做笔记. 摘要: 1.UIPickVIew 几个重要的属性 (1)datePickerMode UIDatePickerModeTime, // Displays hour, mi ...

  6. UIPickView的基本使用

    UIPickView和TableView一样,想要展示数据也要设置数据源和代理设置数据源self.pickView.dataSource = self;设置代理self.pickView.delega ...

  7. UIPickView之自定义生日键盘和城市键盘

    ////  ViewController.m//  04-键盘处理// // #import "ViewController.h"#import "XMGProvince ...

  8. 自定义UIPickView

    效果图 源码 https://github.com/YouXianMing/Animations 说明 1. 数据适配器PickerViewDataAdapter含有PickerViewCompone ...

  9. ios之UIPickView

    以下为控制器代码,主要用到的是UIPickerView 主要步骤:新建一个Single View Application 然后,如上图所示,拖进去一个UILabel Title设置为导航,再拖进去一个 ...

随机推荐

  1. 学习最短路建图 HUD 5521

    http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意:有n个点,m个集合,每个集合里面的点都两两可达且每条边权值都是val,有两个人A, B,A在po ...

  2. MFC下对串口的操作以及定时器的调用

    最近研究了一下MFC下对串口的操作,测试了一下对设备的读写. 1.打开串口 GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(FALSE); m_hComm = ...

  3. oracle数据库的数据类型

    一.字符类型 (1)固定长度的字符串 CHAR(字节长度是1~2000之间) CHAR(8)可以存储4个双字节的字符,8个单字节的字符,不足8字节剩余的部分用空格占据 (2)可变长度字符串 VARCH ...

  4. Sublime console installation instructions install Package Control

    instructions: import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1 ...

  5. TP4056大电流1A使用注意事项

    源:TP4056大电流1A使用注意事项 TP4056为南京拓微集成电路有限公司推出的锂电池充电产品系列中的大电流充电产品.具有最大电流1A,峰值电流1.1A,良好环境下甚至峰值1.2A的单节锂离子电池 ...

  6. 动态链接库dll,导入库lib,静态链接库lib

    目前以lib后缀的库有两种,一种为静态链接库(Static Libary,以下简称“静态库”),另一种为动态连接库(DLL,以下简称“动态库”)的导入库(Import Libary,以下简称“导入库” ...

  7. Webkit之资源加载

    一.webkit资源分类 webkit中有多种资源,大致分为以下几种: HTML文本 CSS样式文本 - CachedCSSStyleSheet 字体 - CachedFont 图片 - Cached ...

  8. 闭包 -> map / floatMap / filter / reduce 浅析

    原创: 转载请注明出处 闭包是自包含的函数代码块,可以在代码中被传递和使用 闭包可以捕获和存储其所在上下文中任意常量和变量的引用.这就是所谓的闭合并包裹着这些常量和变量,俗称闭包.Swift 会为您管 ...

  9. PHP的PDO操作实例

    try{             $dbms='mysql';          //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数       $host='127 ...

  10. BCDBOOT命令参数介绍

    BCDboot 命令行选项 更新时间: 2013年10月 应用到: Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R ...