• .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. ios中关于UIImagePickerController的一些知识总结

    记得添加MobileCoreServices.framework 及导入#import <MobileCoreServices/MobileCoreServices.h> @interfa ...

  2. Jquery-获取勾选的checkbox的同级节点数量

    // 获取勾选的标签值得上一个兄弟节点 var groups = []; $('input[name="group_name"]:checked').siblings(" ...

  3. C++ concepts: Compare

    The concept Compare is a set of requirements expected by some of the standard library facilities fro ...

  4. oracle递归查询子节点

    通过子节点向根节点追朔. select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid 通过根节 ...

  5. Stammering Aliens

    Stammering Aliens Time Limit: 2000MS   Memory Limit: 65536K       Description Dr. Ellie Arroway has ...

  6. 关于Arduino 步进电机Stepper库的一些想法

    官方提供了一些库,使Arduino入门起来更加快速,我们连原理都不用懂,就能通过函数控制终端.但是,这样也带来了很多的缺陷,比如,库函数的功能有限,有些无法实现.然后还有库函数因为要考虑其他的情况,你 ...

  7. PHP 实现定时任务的几种方法

    一. 简单直接不顾后果型 <?php ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limi ...

  8. JS-运动基础(一)

    <title>无标题文档</title> <style> #div1{width:200px;height:200px; background:red; posit ...

  9. CodeForces#378--A, B , D--暴力出奇迹....

    A题 A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes in ...

  10. Windows API 之 CreateThread、WaitForSingleObject(未完)

    WaitForSingleObject Waits until the specified object is in the signaled state or the time-out interv ...