#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. vs2012 jsoncpp 链接错误

    解决: 项目->属性->C/C++->代码生成->运行库->设置与使用的.lib的版本一致.

  2. 151. [USACO Dec07] 建造路径

    ★★   输入文件:roads.in   输出文件:roads.out   简单对比 时间限制:1 s   内存限制:128 MB 译 by CmYkRgB123 描述 Farmer John 刚刚得 ...

  3. windows 下完全卸载service

    用SC Delete命令的话,如果服务名称中带空格,则请在服务名称前面用半角的双引号括起,如SC delete "Adobe LM Service",另外Services这个子键一 ...

  4. POJ_3565_Ants

    题意:给出N个白点和N个黑点,要求用N条不相交的线段把它们连接起来,其中每条线段恰好连接一个白点和一个黑点,每个点恰好连接到一条线段. 分析:因为有结点黑白两色,我们不难想到构造一个二分图,其中每个白 ...

  5. JS函数assign

    Object函数提供了一个叫做assign的函数,用来合并多个对象. Object.assign(...): 你可以传递多个对象给该函数,这些对象中的自有且可枚举的属性,会被拷贝给第一个对象. var ...

  6. jenkins部署遇到离线问题如何解决

    部署jenkins页面时遇到离线问题如何解决 部署jenkins遇到一个问题,然后告诉我你的jenkins已经离线,什么鬼,后来找了很多博客 后来自己终于验证成功了,也分享给大家,只需把https改为 ...

  7. 操作Session存储对象时的一些问题

    前段时间在操作Session存储的对象时,遇到了类似以下的这种情况: User user=new User("张三"); //创建一个姓名为“张三”的User对象 Session[ ...

  8. Ztree加载完成默认选中根节点右侧生成表格

    需求:页面加载完成之后,默认选中ztree的根节点,并执行其点击方法,右侧生成表格: 效果:如下图所示: 思路:在节点点击事件clickNode方法中根据节点的部门code查询这个部门下的所有员工,并 ...

  9. 用php生成HTML文件的类

    目的 用PHP生成HTML文档, 支持标签嵌套缩进, 支持标签自定义属性 起因 这个东西确实也是心血来潮写的, 本来打算是输出HTML片段用的, 但后来就干脆写成了一个可以输出完整HTML的功能; 我 ...

  10. circumferential averge streamwise velocity using Tecplot and Matlab

    Input: results from solver output: circumferential averge physical quantities( such as streamwise ve ...