//
// ViewController.m
// IOS_0107_finalToolClass
//
// Created by ma c on 16/1/7.
// Copyright (c) 2016年 博文科技. All rights reserved.
// #import "ViewController.h"
#import "NotificationViewController.h"
#import "DelegatePassValueViewController.h" @interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate,PassValueDelegate>
// 日期拾取器
@property (strong, nonatomic) UIDatePicker *datePicker;
@property (strong, nonatomic) UILabel *lblShowDate; // 拾取器
@property (strong, nonatomic) UIPickerView *pickerView;
@property (strong, nonatomic) UILabel *lblShowPickerView;
@property (strong, nonatomic) UILabel *lblShowPickerView1;
@property (strong, nonatomic) UILabel *lblShowPickerView2;
@property (strong, nonatomic) UILabel *lblShowPickerView3;
@property (strong, nonatomic) NSMutableArray *pickerDataSource; //动态图
@property (strong, nonatomic) UIImageView *gifImgView; //通知传值
@property (strong, nonatomic) UILabel *lblNotification;
//代理传值
@property (strong, nonatomic) UILabel *lblDelegate; @end @implementation ViewController /*
1.日期拾取器:UIDatePicker
2.拾取器: UIPickerView
3.动态图:
4.通知传值:
5.代理传值:ps-Block(界面传值)
6.网页视图: UIWebView js + oc 混合开发
java + oc 混合开发
HTML + oc 混合开发 */ - (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
//[self createDatePicker];
//[self createPickerView];
//[self createGifImageView];
//[self createNotificationByValue];
//[self createDelegatePassValue];
[self createWebView];
}
#pragma mark - 网页视图
- (void)createWebView
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; //创建[全球支援定位器]
NSURL *baiduURL = [NSURL URLWithString:@"http://www.baidu.com"]; //创建网络请求
NSURLRequest *baiduRequest = [NSURLRequest requestWithURL:baiduURL]; //网页视图加载[网络请求]
[webView loadRequest:baiduRequest]; //添加网页视图
[self.view addSubview:webView];
} #pragma mark - 代理传值 - (void)createDelegatePassValue
{
//创建传递消息的Label
self.lblDelegate = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.lblDelegate.backgroundColor = [UIColor orangeColor];
self.lblDelegate.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:self.lblDelegate];
//创建跳转按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"gotoNextView" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor purpleColor]];
[btn addTarget:self action:@selector(detegatePassValue) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; } - (void)detegatePassValue
{
DelegatePassValueViewController *delegateVC = [[DelegatePassValueViewController alloc] init];
//设置代理传值界面的delegate是当前的VC
delegateVC.delegate = self; [self presentViewController:delegateVC animated:YES completion:nil];
}
//代理传值的协议方法- 回调方法
- (void)my_passValue:(NSString *)str
{
self.lblDelegate.text = str;
} #pragma mark - 通知传值
- (void)createNotificationByValue
{
//创建传递消息的Label
self.lblNotification = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.lblNotification.backgroundColor = [UIColor orangeColor];
self.lblNotification.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:self.lblNotification];
//创建跳转按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"gotoNextView" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor purpleColor]];
[btn addTarget:self action:@selector(gotoNextView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; //想通知中心注册观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getSecret:) name:@"passValue" object:nil]; }
// 通知回调
- (void)getSecret:(NSNotification *)notification
{
if ([notification.object isKindOfClass:[NSString class]]) {
self.lblNotification.text = notification.object;
}
}
//通知传值按钮关联方法
- (void)gotoNextView
{
NotificationViewController *notificationVC = [[NotificationViewController alloc] init];
[self presentViewController:notificationVC animated:YES completion:nil];
}
#pragma mark - gif动态图
- (void)createGifImageView
{
self.gifImgView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
//创建图片数组
NSMutableArray *imgArr = [NSMutableArray array];
for (int i = ; i < ; i++) {
//获取图片名称
NSString *imgName = [NSString stringWithFormat:@"0%dda.png",i];
//根据图片名称获取图片
UIImage *image = [UIImage imageNamed:imgName];
//把图片加载到图片数组中
[imgArr addObject:image];
}
//设置动画图片
[self.gifImgView setAnimationImages:imgArr];
//播放时间
[self.gifImgView setAnimationDuration:];
//重复次数
[self.gifImgView setAnimationRepeatCount:];
//开启动画
[self.gifImgView startAnimating];
[self.view addSubview:self.gifImgView];
} #pragma mark - 拾取器
- (void)createPickerView
{
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(, , , )];
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
[self.view addSubview:self.pickerView]; NSArray *arr1 = @[@"苹果",@"香蕉",@"橘子",@"葡萄",@"菩提"];
NSArray *arr2 = @[@"汽车",@"飞机",@"轮船",@"自行车",@"呵呵"];
NSArray *arr3 = @[@"",@"",@"",@"",@""]; self.pickerDataSource = [[NSMutableArray alloc] initWithObjects:arr1,arr2,arr3, nil];
//拾取器显示标签
self.lblShowPickerView = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
[self.lblShowPickerView setBackgroundColor:[UIColor orangeColor]];
self.lblShowPickerView.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:self.lblShowPickerView];
//拾取器显示标签arr1
self.lblShowPickerView1 = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
[self.lblShowPickerView1 setBackgroundColor:[UIColor orangeColor]];
self.lblShowPickerView1.textAlignment =NSTextAlignmentCenter;
[self.lblShowPickerView addSubview:self.lblShowPickerView1]; //拾取器显示标签arr2
self.lblShowPickerView2 = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
[self.lblShowPickerView2 setBackgroundColor:[UIColor orangeColor]];
self.lblShowPickerView2.textAlignment =NSTextAlignmentCenter;
[self.lblShowPickerView addSubview:self.lblShowPickerView2]; //拾取器显示标签arr3
self.lblShowPickerView3 = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
[self.lblShowPickerView3 setBackgroundColor:[UIColor orangeColor]];
self.lblShowPickerView3.textAlignment =NSTextAlignmentCenter;
[self.lblShowPickerView addSubview:self.lblShowPickerView3]; }
#pragma mark - 拾取器的数据源方法
// 创建分组
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return self.pickerDataSource.count;
}
// 创建分行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [[self.pickerDataSource objectAtIndex:component] count]; }
#pragma mark - 拾取器的代理方法
// 设置组宽
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
return ;
}
// 设置行高
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return ;
}
// 设置行内容
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [[self.pickerDataSource objectAtIndex:component] objectAtIndex:row];
}
// 选中内容后调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (component) {
case :
self.lblShowPickerView1.text = [[self.pickerDataSource objectAtIndex:component] objectAtIndex:row];
break;
case :
self.lblShowPickerView2.text = [[self.pickerDataSource objectAtIndex:component] objectAtIndex:row];
break;
case :
self.lblShowPickerView3.text = [[self.pickerDataSource objectAtIndex:component] objectAtIndex:row];
break; default:
break;
}
} #pragma mark - 日期拾取器
- (void)createDatePicker
{
//日期拾取器(ps:拾取器的高度锁定不变)
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(, , , )];
//不管设置日期拾取器的日期格式如何,拾取器实际确定的时间都是完整的时刻
self.datePicker.datePickerMode = UIDatePickerModeDate;
[self.datePicker setDate:[NSDate date]];
[self.datePicker addTarget:self action:@selector(dateChange) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.datePicker];
//日期显示标签
self.lblShowDate = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
[self.lblShowDate setBackgroundColor:[UIColor orangeColor]];
self.lblShowDate.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:self.lblShowDate];
}
#pragma mark - 日期拾取器关联方法
- (void)dateChange
{
NSLog(@"%@",self.datePicker.date);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:MM:ss"];
NSString *dateStr = [formatter stringFromDate:self.datePicker.date];
self.lblShowDate.text = dateStr; } #pragma mark - 状态栏 - (BOOL)prefersStatusBarHidden
{
return YES;
} @end
 #import <UIKit/UIKit.h>

 @interface NotificationViewController : UIViewController

 @end

 #import "NotificationViewController.h"

 @interface NotificationViewController ()

 @end

 @implementation NotificationViewController

 - (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor cyanColor]]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"passValue" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor purpleColor]];
[btn addTarget:self action:@selector(passValue) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; }
- (void)passValue
{
//返回上一次模态视图
[self dismissViewControllerAnimated:YES completion:nil]; NSString *str = @"here is a secret"; //发送带消息的通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"passValue" object:str];
} @end
 #import <UIKit/UIKit.h>

 @protocol PassValueDelegate <NSObject>

 - (void)my_passValue:(NSString *)str;

 @end

 @interface DelegatePassValueViewController : UIViewController

 //实现协议的代理
@property(strong, nonatomic) id<PassValueDelegate> delegate; @end #import "DelegatePassValueViewController.h" @interface DelegatePassValueViewController () @end @implementation DelegatePassValueViewController - (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor cyanColor]]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"passValueBack" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor purpleColor]];
[btn addTarget:self action:@selector(passValueBack) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)passValueBack
{
[self dismissViewControllerAnimated:YES completion:nil]; NSString *str = @"another secret";
//让代理执行协议方法
if ([self.delegate respondsToSelector:@selector(my_passValue:)]) {
[self.delegate performSelector:@selector(my_passValue:) withObject:str];
}
} @end

笔记

 一.UIPickerView
.UIPickerView的常见属性
// 数据源(用来告诉UIPickerView有多少列多少行)
@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;
// 代理(用来告诉UIPickerView每1列的每1行显示什么内容,监听UIPickerView的选择)
@property(nonatomic,assign) id<UIPickerViewDelegate> delegate;
// 是否要显示选中的指示器
@property(nonatomic) BOOL showsSelectionIndicator;
// 一共有多少列
@property(nonatomic,readonly) NSInteger numberOfComponents; .UIPickerView的常见方法
// 重新刷新所有列
- (void)reloadAllComponents;
// 重新刷新第component列
- (void)reloadComponent:(NSInteger)component; // 主动选中第component列的第row行
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; // 获得第component列的当前选中的行号
- (NSInteger)selectedRowInComponent:(NSInteger)component; .数据源方法(UIPickerViewDataSource)
// 一共有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 第component列一共有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; .代理方法(UIPickerViewDelegate)
// 第component列的宽度是多少
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
// 第component列的行高是多少
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component; // 第component列第row行显示什么文字
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; // 第component列第row行显示怎样的view(内容)
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view; // 选中了pickerView的第component列第row行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; 二.UIDatePicker
.常见属性
// datePicker的显示模式
@property (nonatomic) UIDatePickerMode datePickerMode;
// 显示的区域语言
@property (nonatomic, retain) NSLocale *locale; .监听UIDatePicker的选择
* 因为UIDatePicker继承自UIControl,所以通过addTarget:...监听 三.程序启动的完整过程
.main函数 .UIApplicationMain
* 创建UIApplication对象
* 创建UIApplication的delegate对象 .delegate对象开始处理(监听)系统事件(没有storyboard)
* 程序启动完毕的时候, 就会调用代理的application:didFinishLaunchingWithOptions:方法
* 在application:didFinishLaunchingWithOptions:中创建UIWindow
* 创建和设置UIWindow的rootViewController
* 显示窗口 .根据Info.plist获得最主要storyboard的文件名,加载最主要的storyboard(有storyboard)
* 创建UIWindow
* 创建和设置UIWindow的rootViewController
* 显示窗口

iOS UI-UIPickerView(拾取器)、UIWebView(网页视图)和传值方式的更多相关文章

  1. [Swift通天遁地]一、超级工具-(5)使用UIWebView(网页视图)加载本地页面并调用JavaScript(脚本)代码

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. [Swift通天遁地]一、超级工具-(4)使用UIWebView(网页视图)加载HTML和Gif动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. ios学习之UIWebView网页视图

    转载于爱德凡的百度空间,地址:http://hi.baidu.com/aidfan/item/34a720866b33cbcdef083d37 UIWebView 使用详解 一.UIWebView加载 ...

  4. iOS 浅谈MVC设计模式及Controllers之间的传值方式

    1.简述你对MVC的理解? MVC是一种架构设计.它考虑了三种对象:Model(模型对象).View(试图对象).Controller(试图控制器) (1)模型:负责存储.定义.操作数据 (2)视图: ...

  5. ios学习之UIWebView网页视图调整

    //先来一个可行的小Demo程序:结合searchBar的google搜索 #import <UIKit/UIKit.h> @interface ViewController : UIVi ...

  6. iOS UI基础-15.0 UIWebView

    WebView介绍 知识点: 代码创建一个UIWebView OC调用html的js js页面调用OC 相关代码实现 代码创建一个UIWebView // 1.webView UIWebView *w ...

  7. Django内置auth模块中login_required装饰器用于类视图的优雅方式

    使用多继承 以及类似java中的静态代理模式 原理:OrderView.as_view()根据广度优先,调用的是LoginRequiredMixin中的as_view(cls, *args, **kw ...

  8. Asp.Net Core MVC控制器和视图之间传值

    一.Core MVC中控制器和视图之间传值方式和Asp.Net中非常类似 1.弱类型数据:ViewData,ViewBag 2.强类型数据:@model 二.代码 实例  1.ViewData pub ...

  9. iOS:网页视图控件UIWebView的详解

    网页视图控件:UIWebView 功能:它是继承于UIView的,是一个内置的浏览器控件,以用来浏览从网络下载下来的网页或者本地上加载下来的文档. 枚举: //网页视图导航类型 typedef NS_ ...

随机推荐

  1. JavaScript 获取和修改 内联样式

    JavaScript 获取和修改 内联样式 版权声明:未经授权,严禁转载分享! 元素的样式 HTML 元素的 style 属性返回一个 CSSStyleDeclaration 类型的对象. Style ...

  2. 20145118 《Java程序设计》 实验报告二

    实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.没有Lin ...

  3. 20145327 《网络对抗》MSF基础应用

    20145327 <网络对抗>MSF基础应用 主动攻击ms08_067 两台虚拟机,其中一台为kali,一台为windows xp sp3(英文版) kali ip地址:192.168.4 ...

  4. Python3基础 try-指定except-as reason 捕获打开一个不存在的文件的时候,会产生OSError异常的示例

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. 【第四章】 springboot + swagger

    注:本文参考自 http://www.jianshu.com/p/0465a2b837d2 swagger用于定义API文档. 好处: 前后端分离开发 API文档非常明确 测试的时候不需要再使用URL ...

  6. YOLOv3-darknet 内容解析

    目录 Yolov3-darknet 内容解析 多标签分类预测 跨尺度预测 网络结构改变 reference Yolov3-darknet 内容解析 YOLOv3是到目前为止,速度和精度最均衡的目标检测 ...

  7. HTTP 随笔

    浏览器发送HTTP请求主要分为三部分请求行,Response Headers(响应头信息)和Request Headers(请求头信息). 请求行有分为三部分:请求方法,请求路径和请求协议 请求方法有 ...

  8. BZOJ 1189 【HNOI2007】 紧急疏散evacuate

    题目链接:紧急疏散 这薄脊题我代码不知不觉就写长了…… 这道题二分答案显然,然后用最大流\(check\)即可.设当前二分的答案为\(x\),那么把每扇门拆成\(x\)个点,第\(i\)个代表在第\( ...

  9. python 元组查找元素返回索引

    #create a tuple tuplex = tuple("index tuple") print(tuplex) #get index of the first item w ...

  10. 关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”

    今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '152 ...