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;
}
转载于:https://www.cnblogs.com/pruple/p/5267545.html
UIScroll和UIPickView相关推荐
- UIPickView 和 UIDatePicker
UIPickView 和 UIDatePicker 1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往 弹出一个PickerView给他们选择. 2. ...
- IOS UIPickView+sqlite 选择中国所有城市案例
1.案例简介 通过读取文件,将中国所有城市写入sqlite数据库中,现通过UIPickView实现中国所有城市的选择,效果图如下所示 2.城市对象模型 中国所有城市数据请看 http://blog.c ...
- 用UIpickView实现省市的联动
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIPickerViewDataSource ...
- UIScroll View无限循环的超级简单的实现
UIScrollView创建后必须要被添加到其他的视图控制器或者view中.初始化UIScrollView后必须设置contentSize属性,这个属性的值决定了可以滚动的具体的size.因为我们使用 ...
- ios开发瀑布流框架的封装
一:瀑布流框架封装的实现思路:此瀑布流框架的封装仿照tableView的底层实现,1:每个cell的frame的设置都是找出每列的最大y值,比较每列的最大y值,将下一个cell放在最大y值最小的那一列 ...
- iOS pickerView(所有类型一网打尽)
概述 关于PickView的所有类型都在这里 详细 代码下载:http://www.demodashi.com/demo/11017.html 首先看下项目的整体结构: 一.准备工作 UIPicker ...
- UIPikerView的属性和使用方法
UIPikerView的属性 numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents ...
- 这个我过滤概述UIPickerView键盘处理
一.介绍UIPickView和UIDatePicker(了解) 1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往弹出一个PickerView给他们选 ...
- UIPikerView的属性
UIPikerView的属性 1. numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfCompone ...
最新文章
- ha-2:read-project-properties (default) on project
- python软件怎么用-用Python如何打出你的第一个程序
- TypeScript学习笔记1:变量赋值及书写方式
- 用[bx+idata]的方式进行数组的处理
- 【渝粤教育】国家开放大学2018年秋季 2302T供应链管理 参考试题
- android studio查看jar包源码,Android Studio查看源代码报错
- 抄底公式---预测黑马
- 用mysql计算年龄lt;gt;,什么是运算符lt; =gt;在MySQL中?
- Spark RDD、DataFrame和DataSet的区别
- HTTP访问控制(CORS)踩坑小记
- mysql 中文本类型有哪些_mysql数据类型有哪些
- three.js视频教程2022最新
- Arcmap坐标系转换通用教程【简单明了】
- 树莓派 Ubuntu 18.04 启动2.4Ghz或5Ghz热点及部分5G信道启动失败解决方法
- Matlab实现两个矩阵的加法、乘法计算器
- python的pyc反编译
- MySQL获取汉字的拼音首字母
- Python美化桌面—自制桌面宠物
- Sklearn官方文档中文整理4——随机梯度下降和最近邻篇
- java操作word文档(文字,图片,表格添加以及替换操作)