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设置为导航,再拖进去一个 ...
随机推荐
- 拓扑序+dp Codeforces Round #374 (Div. 2) C
http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...
- .net获取根目录的方法集合
编写程序的时候,经常需要用的项目根目录.自己总结如下 .取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法2. ...
- sql server统计字段的值在某些范围内中的个数
有一张表test如下: create table test ( id ,) primary key, num int ) 插入数据: ); ); ); ); ); ); ); ); ); ); ); ...
- TCP数据包结构
源端口号( 16 位):它(连同源主机 IP 地址)标识源主机的一个应用进程.目的端口号( 16 位):它(连同目的主机 IP 地址)标识目的主机的一个应用进程.这两个值加上 IP 报头中的源主机 I ...
- 设置UITabBarController上ImageInsets后点击不断缩小
最近遇到了这样一个情况,客户要求做出这种效果的UITabBarController. 通过各种查询,得出UITabBarController有这样一个属性,是设置它的图片距上下左右距离的属性: nav ...
- ligerUI调用$.ligerDialog.open弹出窗口,关闭后无法获取焦点问题
1:调用父窗口某一个文件框,获取焦点, parent.window.document.getElementByIdx_x("roleName").focus(); 2:关闭父窗 ...
- TabControl选项卡
<Grid> <TabControl Name="tabControl1"> <TabItem Name="tabItem1"&g ...
- C#中:函数访问级别对函数形参访问级别的约束
Inconsistent accessibility: parameter type 'Program.CommandLineInfo' is less accessible than method ...
- 使用nginx简单实现负载均衡
只是简单使用nginx玩玩而已,知道能这么用,但是在实际项目中并没有实践过,在项目不大的时候用不到,但是对于理解负载均衡来说还是可以的. 利用虚拟机安装了三个centOS系统,然后顺便装了环境. 这里 ...
- itext操作PDF文件添加水印
功能描述:添加图片和文字水印 /** * * [功能描述:添加图片和文字水印] [功能详细描述:功能详细描述] * @param srcFile 待加水印文件 * @param destFile 加水 ...