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设置为导航,再拖进去一个 ...
随机推荐
- JS模拟窗口
摘自于网络:http://www.cnblogs.com/joinger/articles/1297228.html <!DOCTYPE html PUBLIC "-//W3C//DT ...
- Hibernate 系列教程12-继承-Join策略
Employee public class Employee { private Long id; private String name; HourlyEmployee public class H ...
- HDU 2802 F(N) 数论+打表
题目大意:f[n]-n^3=f[n-2]-(n-1)^3 (n >=3),f[1]=1,f[2]=7,求f[n]. 题目思路:将n^3移到到等式右边化简的到:f[n]=f[n-2]+3n*(n- ...
- CGRect相关工具函数
NSStringFromCGRect(aCGRect): CGRectFromString(aString):如果把视图的框架以字符串的形式放在NSUserDefaults里面,那么该方法可以将其转回 ...
- 444A/CF
题目链接[http://codeforces.com/problemset/problem/444/A] 题意:给出一个无向图,找出一个联通子图,定义密度#=v(顶点值的和)/e(边值的和). 条件: ...
- XMEAG-128A1
JTAGUSERID = 0x00 WDWP = 8CLK WDP = 8CLK DVSDON = [ ] BOOTRST = BOOTLDR BODPD = DISABLED RSTDISBL = ...
- 【Python初学】深copy&浅copy
在python中,对象赋值实际上是对象的引用.当创建一个对象,然后把它赋给另一个变量的时候,python并没有拷贝这个对象,而只是拷贝了这个对象的引用. 1. copy.copy 浅拷贝 只拷贝父对象 ...
- ACM课程学习总结
ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...
- synchronized关键字以及实例锁 类锁
Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchronized(this ...
- java面向对象_接口
java接口 interface,是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类,编写接口的方式和类很相似,但 ...