• .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. $scope

    $scope.aaa = 3; $scope.bbb = 4; $scope.aaa = $scope.bbb; //这只是简单的赋值 $scope.bbb = 5; 输出 $scope.aaa为4 ...

  2. ignite中的sql查询

    ignite中进行sql查询需要对要查询的cache和字段进行配置,可以在xml中配置,也可以在代码中配置或进行注解,我用的是xml配置: <!-- 配置cache --> <pro ...

  3. phpstudy 安装memcached服务和memcache扩展

    memcached安装步骤: 首先,将下载好的memcahed解压到某个文件目录下,例如 C:\memcached 然后,在cmd里,输入"C:\memcached\memcached.ex ...

  4. mysql Group By

    1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简 ...

  5. pur-ftpd在ubuntu上的安装

    1.安装 apt-get install pure-ftpd 2.建立ftp目录 /var/ftp/public 3.建立ftp用户组 groupadd ftpgroup 4.建立ftp非系统用户 u ...

  6. openstack镜像如何在vmware 环境中运行

    1.云镜像文件下载地址: http://sahara-files.mirantis.com/sahara-juno-spark-1.0.0-ubuntu-14.04.qcow2(安装有sahara-s ...

  7. JavaScript(四)---- 函数

    函数主要用来封装具体的功能代码. 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 格式: function 函数名(形参列表){         ...

  8. C# Excel嵌入到Winform

    本文讲的这个技术是把Excel表格嵌入到自己开发程序的Form窗体中进行操作,给客户一个不用切换窗口的操作界面,似乎更好.这在VC中用OLE技术很容易实现,但是在C#中方法就不一样啦.下面将就此进行阐 ...

  9. HTML5来了:5个好用的混合式App开发工具

    在残酷的移动互联网竞争环境下, HTML5技术一直受到各方关注,“HTML5颠覆原生 App”的争论也从未停止过,不管怎样HTML5生态的构建方兴未艾.不过对于移动开发者来说更关心的问题是如何低成本. ...

  10. BZOJ 1196 二分答案+并查集

    http://www.lydsy.com/JudgeOnline/problem.php?id=1196 题目大意:n个城市,m-1条路,每条路有一级公路和二级公路之分,你要造n-1条路,一级公路至少 ...