iOS-UITextView-文本输入视图的使用
#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-文本输入视图的使用的更多相关文章
- IOS UITextView支持输入、复制、粘贴、剪切自定义表情
UITextView是ios的富文本编辑控件,除了文字还可以插入图片等.今天主要介绍一下UITextView对自定义表情的处理. 1.首先识别出文本中的表情文本,然后在对应的位置插入NSTextAtt ...
- iOS UITextView 根据输入text自适应高度
转载自:http://www.cnblogs.com/tmf-4838/p/5380495.html #import "ViewController.h" @interface V ...
- iOS中 UITextView文本视图 技术分享
UITextView: 文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文. UITextField的用处多,UITextView的用法也不 ...
- iOS:文本视图控件UITextView的详细使用
文本视图控件:UITextView 介绍:它是一个文本域的编辑视图,可以在该区域上进行编辑(包括删除.剪贴.复制.修改等),它与文本框UITextField的不同之处是:当它里面的每一行内容超出时,可 ...
- UITextView(文本视图) 学习之初体验
UITextView文本视图相比与UITextField直观的区别就是UITextView可以输入多行文字并且可以滚动显示浏览全文.常见UITextView使用在APP的软件简介.内容详情显示.小说阅 ...
- iOS,文本输入,键盘相关
1.UIKeyboard键盘相关知识点 2.点击空白区域隐藏键盘(UIKeyboard) 3.键盘(UIKeyboard)挡住输入框处理 4.自定义键盘(UIKeyboard) 5.监听键盘弹出或消失 ...
- iOS UITextView 输入内容实时更新cell的高度
iOS UITextView 输入内容实时更新cell的高度 2014-12-26 11:37 编辑: suiling 分类:iOS开发 来源:Vito Zhang'blog 11 4741 UIT ...
- 最全的Swift社交应用文本输入优化汇总
在大部分应用中,都有输入的需求,面对众多用户,他们的想法各异,输入的文本内容也是千奇百怪,面对不同的输入,我们该如何优化输入体验?本文将汇总一下Swift社交应用文本输入优化技巧. AD: 一.输入相 ...
- IOS UITextView自适应高度
LOFTER app需要实现了一个类似iPhone短信输入框的功能,它的功能其实蛮简单,就是:[UITextView的高度随着内容高度的变化而变化].实现思路应该是: 在UITextView的text ...
- Xamarin iOS教程之自定义视图
Xamarin iOS教程之自定义视图 Xamarin iOS自定义视图 工具栏中的视图在实际应用开发中用的很多,但是为了吸引用户的眼球,开发者可以做出一些自定义的视图. [示例2-33]以下将实现一 ...
随机推荐
- Android RecyclerView嵌套EditView实时更新Item数据
一.场景(例如:购物车) 1.当我们需要以列表样式管理某些数据时,可能需要列表项的某个字段可编辑 2.编辑Item上的某个字段后可能还要更新相关字段的值 二.可能遇到的问题 1.列表滑动导致输入框中的 ...
- Tomcat无法clean,无法remove部署的项目
错误: 对部署在Tomcat下的项目进行clean操作,总是提示Could not load the Tomcat server configuration,错误信息如图: 解决: 原来是将Serve ...
- PHP开发心得四
1,php返回给html页面的Json数据不能含有回车符 某次用php编写查询数据库数据,以json格式返回给前端页面js文件,js文件以angularJS的函数调用处理的方式进行数据显示,但数据返回 ...
- php经典bug
<?php $tem = 0=="a"?1:2; echo $tem; ?> 输出结果为:1 原因:在0=="a",这个比较中因为会将字符串&quo ...
- 【转载】 python sort、sorted高级排序技巧
这篇文章主要介绍了python sort.sorted高级排序技巧,本文讲解了基础排序.升序和降序.排序的稳定性和复杂排序.cmp函数排序法等内容,需要的朋友可以参考下 Python list内置so ...
- C++ 泛型程序设计与STL模板库(1)---泛型程序设计简介及STL简介与结构
泛型程序设计的基本概念 编写不依赖于具体数据类型的程序 将算法从特定的数据结构中抽象出来,成为通用的 C++的模板为泛型程序设计奠定了关键的基础 术语:概念 用来界定具备一定功能的数据类型.例如: 将 ...
- ARX亮显问题
转载一段acedSSSetFirst的用法仅供参考:打个比方,我创建了一个命令,这个命令的功能是提示用户选择,然后只过滤文本对象作为选择集,随后在屏幕上使得这个选择集的所有成员都亮显,并且能够显示出各 ...
- CAD使用GetxDataLong读数据(网页版)
主要用到函数说明: MxDrawEntity::GetxDataLong2 读取一个Long扩展数据,详细说明如下: 参数 说明 [in] LONG lItem 该值所在位置 [out, retval ...
- HDU多校Round 5
Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...
- Java真实笔试题一
PS:昨天去笔试后,发现自己对于JavaSE的基础部分还是有些薄弱的地方,特将昨天自己不是太清楚的地方记录下来,巩固基础. 子类继承父类静态方法的问题 public class Study { pub ...