UITextView自适应高度
来源:互联网 发布:yes淘宝刷信用 编辑:程序博客网 时间:2024/05/17 06:25
之前textView算文字高度总是拿不到合适的高度。在Stack Overflow 找到了解决方法备注在此。
代码如下:
UITextView * textView=[[UITextView alloc] initWithFrame:CGRectMake(20, 40, self.view.frame.size.width-40, 20)]; textView.text=@" I'm porting one of apps from iOS 6.1 to iOS 7. I'm using a layout where there's a UITextView that has a fix width, but it's height is based on its contentsize. For iOS 6.1 checking the contentsize.height and setting it as the textview's frame height was enough, but it doesn't work on iOS 7.\n How can i then create a UITextView with a fixed width, but dynamic height based on the text it's showing? \n"; textView.textColor=[UIColor brownColor]; textView.font=[UIFont systemFontOfSize:14.0]; textView.layer.borderColor=[[UIColor lightGrayColor] CGColor]; textView.layer.borderWidth=1.0f; [self.view addSubview:textView]; CGFloat fixedWidth = textView.frame.size.width; CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; CGRect newFrame = textView.frame; newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); textView.frame = newFrame;下面是这个demo:
0 0
- UILabel, UITextView 高度自适应
- IOS UITextView自适应高度
- IOS UITextView自适应高度
- iOS:UITextView自适应高度
- UILabel, UITextView 高度自适应
- IOS UITextView自适应高度
- UITextView自适应高度
- IOS UITextView自适应高度
- UITextView自适应高度
- IOS UITextView自适应高度
- UILabel和UITextView自适应高度
- UILabel、UITextView自适应得到高度
- UILabel和UITextView自适应高度
- UILabel、UITextView自适应得到高度
- UILabel和UITextView自适应高度
- UILabel、UITextView自适应得到高度
- iOS--UITextView的高度自适应
- UITextView文字自适应显示高度
- 黑马程序员------------反射技术
- Linux进程间通信——信号
- android压缩照片到指定大小100%可靠
- 利用predis操作redis方法大全
- Oracle 中的 TO_DATE 和 TO_CHAR 函数 日期处理
- UITextView自适应高度
- IT企业专利工程师之三:计算机技术领域专利挖掘刍议
- 习题3—17
- MFC 界面部件大小位置自适应 EasySize的使用
- Android相关书签
- nodejs读取url中格式为数组的参数
- 第三章第10题
- A/B表替1对多关系,要求联合查询B表只提取一条与A记录关联的记录
- nyoj257郁闷的c小加(一)(栈和队列)