iOS UITextView根据输入的文字自动变换高度
来源:互联网 发布:驱动软件 知乎 编辑:程序博客网 时间:2024/05/16 22:02
self.contentTextView = [[UITextView alloc]initWithFrame:CGRectMake((kMainBoundsWidth-250)/2, kMainBoundsHeight/2-50, 250, 39)]; self.contentTextView .layer.cornerRadius = 4; self.contentTextView .layer.masksToBounds = YES; self.contentTextView .delegate = self; self.contentTextView .layer.borderWidth = 1; self.contentTextView .font = [UIFont systemFontOfSize:14]; self.contentTextView .layer.borderColor = [[[UIColor lightGrayColor] colorWithAlphaComponent:0.4] CGColor]; //加下面一句话的目的是,是为了调整光标的位置,让光标出现在UITextView的正中间 self.contentTextView.textContainerInset = UIEdgeInsetsMake(10,0, 0, 0); [self.view addSubview:self.contentTextView ];
- (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText{ CGSize constraint = CGSizeMake(textView.contentSize.width , CGFLOAT_MAX); CGRect size = [strText boundingRectWithSize:constraint options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil]; float textHeight = size.size.height + 22.0; return textHeight;}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ CGRect frame = textView.frame; float height; if ([text isEqual:@""]) { if (![textView.text isEqualToString:@""]) { height = [ self heightForTextView:textView WithText:[textView.text substringToIndex:[textView.text length] - 1]]; }else{ height = [ self heightForTextView:textView WithText:textView.text]; } }else{ height = [self heightForTextView:textView WithText:[NSString stringWithFormat:@"%@%@",textView.text,text]]; } frame.size.height = height; [UIView animateWithDuration:0.5 animations:^{ textView.frame = frame; } completion:nil]; return YES;}
0 0
- iOS UITextView根据输入的文字自动变换高度
- iOS:如何优雅的让UITextView根据输入文字实时改变高度
- iOS:如何优雅的让UITextView根据输入文字实时改变高度
- ios 文字 控件 自适应 高度 宽度 CustomCell 自适应高度+uilabel自动换行+ UITextView 根据内容自动调整高度
- 设置textView根据输入的文字自动增加高度
- UITextview 根据输入的内容动态改变高度
- 自动根据键盘位置调整UITextView的高度
- iOS根据文字计算控件的高度
- iOS UITextView 输入内容实时更新cell的高度
- iOS UITextView 输入内容实时更新 Cell 的高度
- iOS UITextView 输入内容实时更新cell的高度
- iOS UITextView 输入内容实时更新cell的高度
- iOS UITextView 输入内容实时更新cell的高度
- iOS UITextView 输入内容实时更新cell的高度
- iOS UITextView 输入内容实时更新 cell 的高度
- iOS UITextView输入时自适应高度,placeholderLabel的设置。
- iOS根据字符串计算UITextView高度
- iOS根据字符串计算UITextView高度
- Ubuntu16.04初次安装(Windows10与Ubuntu16.04双系统_UEFI)
- Session 的生命周期和工作原理
- 客户端登录添加token机制
- MySQL MMM架构搭建
- 同步方法与同步块的区别
- iOS UITextView根据输入的文字自动变换高度
- spark streaming实例编写
- PHP相关系列 - 优化你的PHP代码
- QML中引用全局枚举类型
- DebugView使用笔记
- H.264句法和语法总结(五)片头句法
- 数组与arrayList相互转换
- Linux下配置两个或多个Tomcat启动
- Java获取当月最后3天或几天