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]以下将实现一 ...
随机推荐
- 连接服务器的mysql
在服务器配置好Mysql 数据库,在客户端连接,报错: 解决方法: 1.在MySQL 数据库中修改user表,将host 中的localhoust 改为 %: 2.配置访问数据库的全选 根据需要配置权 ...
- JS实现LOGO像雪花一样落下特效
<HTML><HEAD><TITLE>LOGO从上落下</TITLE> <SCRIPT language=JavaScript> //窗口改 ...
- Java学习2_一些基础2_字符串_16.5.5
接上一次的博客. 不可变字符串: Java中String类没有提供用于修改字符串的方法.如果想将greeting中的“Hello”改为“Help!”需要先提取所需要的的字符,然后再拼接.即 greet ...
- 15 AJAX
AJAX AJAX 简介 AJAX 是 异步 JavaScript 及 XML(Asynchronous JavaScript and XML)的缩写.AJAX 不是一种新的编程语言,而是一种用于创 ...
- (转)MySQL中的索引详讲
序言 之前写到MySQL对表的增删改查(查询最为重要)后,就感觉MySQL就差不多学完了,没有想继续学下去的心态了,原因可能是由于别人的影响,觉得对于MySQL来说,知道了一些复杂的查询,就够了,但是 ...
- Linux内核-内存回收逻辑和算法(LRU)
Linux内核内存回收逻辑和算法(LRU) LRU 链表 在 Linux 中,操作系统对 LRU 的实现主要是基于一对双向链表:active 链表和 inactive 链表,这两个链表是 Linux ...
- @Inherited注解
允许子类继承父类的注解 https://blog.csdn.net/renli2549/article/details/78432272
- java基础学习日志---File方法分析
package FunDemo; import java.io.File; import java.io.IOException; import java.util.Arrays; public cl ...
- Linux 安装 Tomcat 详解
说明:安装的 tomcat 为解压版(即免安装版):apache-tomcat-8.5.15.tar.gz (1)使用 root 用户登录虚拟机,在根目录下的 opt 文件夹新建一个 software ...
- python3连接mysql 稍微进阶 + 日期处理
1.踩了个操作中文的坑,结果发现之前的文章中有强调了,在连接处加:charset="utf8" conn = pymysql.connect(host = '127.0.0.1', ...