#import "ViewController.h"

@interface ViewController ()<UITextViewDelegate>

{

UIView *bgView;

UITextView *inputView;

CGRect keyBoardRect;

NSMutableArray *allContent;

}

@end

/*

1.NSDate 时间格式

2.NSTimeInterval 时间间隔
基本单位 秒

3.NSDateFormatter 时间格式器
用于日期对象的格式化或者字符串解析日期为对象

时间戳:

日期格式例如以下:

y  年

M  年中的月份

D  当天是今年的第多少天

d  月份中的天数

F  月份中的周数

E  星期几

a  Am/pm

H  一天中的小时数(0-23)

k  一天中的小时数(1-24)

K  am/pm 中的小时数(0-11)  Number  0

h  am/pm 中的小时数(1-12)  Number  12

m  小时中的分钟数  Number  30

s  分钟中的秒数  Number  55

S  毫秒数  Number  978

z  时区  General time zone  Pacific Standard Time; PST; GMT-08:00

Z  时区  RFC 822 time zone  -0800

4.比較时间:

(1)比較两个日期是不是同一个日期 isEqualToDate

(2)获取较早的日期 earlierDate

(3)获取较晚的时间 lateDate

(4)获取两个日期间隔多少秒

*/

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

allContent = [NSMutableArray array];

//通过通知检測键盘显示的状态

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(keyBoard:) name:UIKeyboardWillHideNotification object:nil];

//须要输入框和其上面的button同一时候上移

bgView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)-40, CGRectGetWidth(self.view.frame), 40)];

bgView.backgroundColor = [UIColor grayColor];

[self.view addSubview:bgView];

inputView = [[UITextView alloc]initWithFrame:CGRectMake(50, 5, 200, 30)];

inputView.layer.cornerRadius = 5;

inputView.delegate = self;

[bgView addSubview:inputView];

UIButton *sendBt = [UIButton buttonWithType:UIButtonTypeCustom];

sendBt.frame = CGRectMake(CGRectGetMaxX(inputView.frame)+20, 5, 80, 30);

[bgView addSubview:sendBt];

sendBt.backgroundColor = [UIColor cyanColor];

[sendBt setTitle:@"发送" forState:UIControlStateNormal ];

[sendBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

sendBt.tag = 100;

sendBt.layer.cornerRadius = 5;

//默认不能够使用button,输入内容后才使用

sendBt.enabled = YES;

[sendBt addTarget:self action:@selector(senContent:) forControlEvents:UIControlEventTouchUpInside];

}

#pragma ------------键盘的状态--------------

- (void)keyBoard:(NSNotification *)not

{

NSDictionary *info = not.userInfo;

//    NSLog(@"%@",info);

keyBoardRect = [info[UIKeyboardFrameEndUserInfoKey]CGRectValue];

bgView.frame = CGRectMake(0, CGRectGetMinY(keyBoardRect)-40, CGRectGetWidth(self.view.frame), 40);

}

#pragma ------------TextViewDelegate方法--------------

- (void)textViewDidBeginEditing:(UITextView *)textView

{

//開始编辑的时候
同意发送button使用

UIButton *button = (UIButton *)[bgView viewWithTag:100];

button.enabled = YES;

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{

//通过检測textView输入的内容得到它的内容高度,把内容的高度设置成inputView的高度以及bgView的高度

bgView.frame = CGRectMake(0, CGRectGetHeight([UIScreen mainScreen].bounds)-textView.contentSize.height-10-CGRectGetHeight(keyBoardRect), CGRectGetWidth([UIScreen mainScreen].bounds), textView.contentSize.height+10);

inputView.frame = CGRectMake(50, 5, 200, textView.contentSize.height);

return YES;

}

#pragma ------------发送输入的内容--------------

- (void)senContent:(UIButton *)sender

{

[inputView resignFirstResponder];

NSLog(@"%@",inputView.text);

inputView.text = @"";

NSDate *curDate = [NSDate date];

NSLog(@"%@",[NSString stringWithFormat:@"%@",curDate]);

//时
分 秒

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];

//设置时间格式

formatter.dateFormat = @"y/M/d E  a hh: mm :ss";

//把curDate依照时间格式
转化成字符串

NSString *time = [formatter stringFromDate:curDate];

//NSDateFormatter 转换的时间
是设备的时间

NSLog(@"%@",time);

//获得从1970年到如今的时间间隔(一般是时间戳的
时间间隔)

NSTimeInterval timeInterval = [curDate timeIntervalSince1970];

NSString *timeString = [NSString stringWithFormat:@"%0.f",timeInterval];

NSLog(@"时间戳:%@",timeString);

//把时间戳
转换成 日期

NSDate *date  = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]];

NSLog(@"时间戳
转时间%@",[formatter stringFromDate:date]);

//获得较早的日期

//NSDate *earDate = [date earlierDate:date];

//通过时间间隔
能够计算未来+ 或者过去的时间-

//NSDate dateWithTimeIntervalSinceNow:
计算当前日期到时间间隔日期

//获得一天的时间间隔

NSTimeInterval interval = 24*60*60;

//设置时间格式为
年 月

NSDate *ysterday = [NSDate dateWithTimeIntervalSinceNow:-interval];

formatter.dateFormat = @"yyyy-MM-dd";

NSLog(@"%@",[formatter stringFromDate:ysterday]);

NSDictionary *info = @{@"content":inputView.text,@"time":time};

[allContent addObject:info];

//指定依据那个key
进行分类

NSSortDescriptor *soreDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:NO];

NSMutableArray *soreDescriptorArry = [NSMutableArray arrayWithObjects:&soreDescriptor count:1];

//依据
描写叙述的数组进行排序

allContent = [[allContent sortedArrayUsingDescriptors:soreDescriptorArry] mutableCopy];

sender.enabled = NO;

NSLog(@"%@",allContent);

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end


iOS-UITextView-文本输入视图的使用的更多相关文章

  1. IOS UITextView支持输入、复制、粘贴、剪切自定义表情

    UITextView是ios的富文本编辑控件,除了文字还可以插入图片等.今天主要介绍一下UITextView对自定义表情的处理. 1.首先识别出文本中的表情文本,然后在对应的位置插入NSTextAtt ...

  2. iOS UITextView 根据输入text自适应高度

    转载自:http://www.cnblogs.com/tmf-4838/p/5380495.html #import "ViewController.h" @interface V ...

  3. iOS中 UITextView文本视图 技术分享

    UITextView: 文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文. UITextField的用处多,UITextView的用法也不 ...

  4. iOS:文本视图控件UITextView的详细使用

    文本视图控件:UITextView 介绍:它是一个文本域的编辑视图,可以在该区域上进行编辑(包括删除.剪贴.复制.修改等),它与文本框UITextField的不同之处是:当它里面的每一行内容超出时,可 ...

  5. UITextView(文本视图) 学习之初体验

    UITextView文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文.常见UITextView使用在APP的软件简介.内容详情显示.小说阅 ...

  6. iOS,文本输入,键盘相关

    1.UIKeyboard键盘相关知识点 2.点击空白区域隐藏键盘(UIKeyboard) 3.键盘(UIKeyboard)挡住输入框处理 4.自定义键盘(UIKeyboard) 5.监听键盘弹出或消失 ...

  7. iOS UITextView 输入内容实时更新cell的高度

    iOS UITextView 输入内容实时更新cell的高度 2014-12-26 11:37 编辑: suiling 分类:iOS开发 来源:Vito Zhang'blog  11 4741 UIT ...

  8. 最全的Swift社交应用文本输入优化汇总

    在大部分应用中,都有输入的需求,面对众多用户,他们的想法各异,输入的文本内容也是千奇百怪,面对不同的输入,我们该如何优化输入体验?本文将汇总一下Swift社交应用文本输入优化技巧. AD: 一.输入相 ...

  9. IOS UITextView自适应高度

    LOFTER app需要实现了一个类似iPhone短信输入框的功能,它的功能其实蛮简单,就是:[UITextView的高度随着内容高度的变化而变化].实现思路应该是: 在UITextView的text ...

  10. Xamarin iOS教程之自定义视图

    Xamarin iOS教程之自定义视图 Xamarin iOS自定义视图 工具栏中的视图在实际应用开发中用的很多,但是为了吸引用户的眼球,开发者可以做出一些自定义的视图. [示例2-33]以下将实现一 ...

随机推荐

  1. Spark学习之基础相关组件(1)

    Spark学习之基础相关组件(1) 1. Spark是一个用来实现快速而通用的集群计算的平台. 2. Spark的一个主要特点是能够在内存中进行计算,因而更快. 3. RDD(resilient di ...

  2. Android Programming 3D Graphics with OpenGL ES (Including Nehe's Port)

    https://www3.ntu.edu.sg/home/ehchua/programming/android/Android_3D.html

  3. python行与缩进

    #python行与缩进 1.了解逻辑行与物理行 2.行中分号使用规则 3.行链接 4.什么是缩进 5.如何缩进 6.注释 1.python中逻辑行主要是指一段代码,在意义上它的行数,而物理行,指的是我 ...

  4. (转)淘淘商城系列——商品搜索功能Dao实现

    http://blog.csdn.net/yerenyuan_pku/article/details/72909286 终于进入商品搜索功能的开发中了,本文我来教大家编写实现商品搜索功能的Dao层代码 ...

  5. iOS布局分类

    1.线性布局: 2.集合布局: 3.单元布局: 需要考虑因素: 空间充足.空间不足时内容.尺寸的取舍.

  6. Vue指令5:v-if

    条件判断(v-if\v-else) v-if 指令将根据表达式的真假值(true 或 false )来决定是否插入 元素. <div id="app"> <ul ...

  7. 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList

    package algorithms; import java.util.ArrayList; import java.util.Stack; /** * public class ListNode ...

  8. org-table

    ‎ Table of Contents 1. table 1.1. 创建方式 1.2. 重新对齐 1.3. 行列编辑 1.4. 区域 1.5. 计算 1.6. 其他的 1.7. 行宽度 1.8. 列分 ...

  9. telnet mysql3306端口失败

    在linux上telnet远程mysql端口失败,经过上网查找后,找到多种方法. (1)我在本地的Navicat上新增了一个用户,主机名是linux的ip,也可以是 %(百分号代表这个用户可以在任何地 ...

  10. 还没更换RubyGems镜像?

    相信用过Ruby的人都知道 gem install 命令,但是在国内该命令安装的速度甚是不稳定(你懂的),导致尝试数次便是等待数时,记得之前在安装redmine的时候便是如此,之前不懂什么意思,还以为 ...