设置textView根据输入的文字自动增加高度
来源:互联网 发布:淘宝开店如何发布商品 编辑:程序博客网 时间:2024/05/16 07:34
#import "CWViewController.h"@interface CWViewController ()<UITextViewDelegate>@end@implementation CWViewController- (void)viewDidLoad{ [super viewDidLoad]; //设置代理对象 self.textView.delegate=self; //初始化textView的文字 self.textView.text=@"1"; self.textView.backgroundColor=[UIColor orangeColor]; // Do any additional setup after loading the view, typically from a nib.}- (void)textViewDidChange:(UITextView *)textView{ NSLog(@"654"); //执行方法 CGSize tempSize = [self sizeWithText:textView.text boundingRectWithSize:CGSizeMake(textView.frame.size.width, 10000000) font:textView.font]; //改变frame textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, tempSize.height);}-(CGSize)sizeWithText:(NSString *)text boundingRectWithSize:(CGSize)boundingSize font:(UIFont *)font{ //段落 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; [paragraphStyle setLineSpacing:5]; //根据输入的文字字体大小设置自动高度 NSDictionary *attributes = [NSDictionary dictionaryWithObjects:@[font,paragraphStyle] forKeys:@[NSFontAttributeName,NSParagraphStyleAttributeName]]; CGSize contentSize = [text boundingRectWithSize:boundingSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size; return contentSize;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- 设置textView根据输入的文字自动增加高度
- iOS UITextView根据输入的文字自动变换高度
- Flex TextArea 根据文字内容自动增加高度
- iOS开发笔记- cell里放textView根据输入的文字动态改变textView以及cell高度
- 类似微信文本输入框实现,底部评论输入View,随着文字的增加,textView自增长高度
- ios 根据文字设置高度
- Android根据文字长度自动调整字号的TextView
- 关于textView根据输入内容自适应高度
- 随着文字内容增加,div的高度也跟着增加,并且文字自动换行
- textView根据字符数自动调整高度
- textview根据字数自动调高度,cell高度自动调节
- iOS 根据文字内容设置cell 的高度
- textarea根据内容自动增加高度
- textview根据文字行数自动变化大小
- TextView的文字设置
- 设置DIV根据内容自动调整高度的三个方法
- 动态设置TextView的高度
- div设置固定高度,超过设置高度则自动增加
- PHP字符串操作常用函数
- 黑马程序员---03引用计数器的基本使用
- 第十三周项目一插入元素
- erlang 继承
- c语言的菜鸟理解到深入学习1--关于printf的小细节printf(s,i);竟然是对的
- 设置textView根据输入的文字自动增加高度
- JAVA数值的深入理解
- 深入浅出Linux-linux出世(3)
- Linux-0.11内核源码分析系列:内存管理try_to_share()与share_page()函数分析
- JS柯里化curry
- poj 2356 暴力或者组合数学
- AsyncDisplayKit教程
- 总结条款:11在operator=中处理“自我赋值”
- OpenGl多重纹理的计算