• .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;

}

转载于:https://www.cnblogs.com/pruple/p/5267545.html

UIScroll和UIPickView相关推荐

  1. UIPickView 和 UIDatePicker

    UIPickView 和 UIDatePicker 1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往 弹出一个PickerView给他们选择. 2. ...

  2. IOS UIPickView+sqlite 选择中国所有城市案例

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

  3. 用UIpickView实现省市的联动

    #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIPickerViewDataSource ...

  4. UIScroll View无限循环的超级简单的实现

    UIScrollView创建后必须要被添加到其他的视图控制器或者view中.初始化UIScrollView后必须设置contentSize属性,这个属性的值决定了可以滚动的具体的size.因为我们使用 ...

  5. ios开发瀑布流框架的封装

    一:瀑布流框架封装的实现思路:此瀑布流框架的封装仿照tableView的底层实现,1:每个cell的frame的设置都是找出每列的最大y值,比较每列的最大y值,将下一个cell放在最大y值最小的那一列 ...

  6. iOS pickerView(所有类型一网打尽)

    概述 关于PickView的所有类型都在这里 详细 代码下载:http://www.demodashi.com/demo/11017.html 首先看下项目的整体结构: 一.准备工作 UIPicker ...

  7. UIPikerView的属性和使用方法

    UIPikerView的属性 numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents ...

  8. 这个我过滤概述UIPickerView键盘处理

    一.介绍UIPickView和UIDatePicker(了解) 1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往弹出一个PickerView给他们选 ...

  9. UIPikerView的属性

    UIPikerView的属性 1. numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfCompone ...

最新文章

  1. ha-2:read-project-properties (default) on project
  2. python软件怎么用-用Python如何打出你的第一个程序
  3. TypeScript学习笔记1:变量赋值及书写方式
  4. 用[bx+idata]的方式进行数组的处理
  5. 【渝粤教育】国家开放大学2018年秋季 2302T供应链管理 参考试题
  6. android studio查看jar包源码,Android Studio查看源代码报错
  7. 抄底公式---预测黑马
  8. 用mysql计算年龄lt;gt;,什么是运算符lt; =gt;在MySQL中?
  9. Spark RDD、DataFrame和DataSet的区别
  10. HTTP访问控制(CORS)踩坑小记
  11. mysql 中文本类型有哪些_mysql数据类型有哪些
  12. three.js视频教程2022最新
  13. Arcmap坐标系转换通用教程【简单明了】
  14. 树莓派 Ubuntu 18.04 启动2.4Ghz或5Ghz热点及部分5G信道启动失败解决方法
  15. Matlab实现两个矩阵的加法、乘法计算器
  16. python的pyc反编译
  17. MySQL获取汉字的拼音首字母
  18. Python美化桌面—自制桌面宠物
  19. Sklearn官方文档中文整理4——随机梯度下降和最近邻篇
  20. java操作word文档(文字,图片,表格添加以及替换操作)

热门文章

  1. 深入理解Tomcat系列之一:系统架构(转)
  2. 快速通过软件设计师考试方法
  3. Python实战之子进程
  4. 蓝桥杯 ALGO-105 算法训练 黑色星期五
  5. 腾达ac9虚拟服务器,腾达AC9官方定制固件1.0版-加广告屏蔽、迅雷等
  6. deville什么意思_欧米茄手表的deville是什么意思?
  7. Java程序员需要注意的五大Docker误区
  8. linux安装mongodb并创建用户
  9. oracle查询:分组查询,取出每组中的第一条记录
  10. Java-Collections的sort方法对 list 进行排序