动态设置TextView的高度

来源:互联网 发布:美业软件免费 编辑:程序博客网 时间:2024/06/04 18:18
//orgSize设置宽度和高度,将需要得到的高度或宽度设置为一个很大的值- (CGFloat)heightForTextView:(UITextView *)textView OrgSize:(CGSize)orgSize{        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {        //需IOS7.0        NSDictionary *dicFont = [NSDictionary dictionaryWithObjectsAndKeys:textView.font, NSFontAttributeName, nil];        CGSize size = [textView.text boundingRectWithSize:orgSize                                                   options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin                                                attributes:dicFont                                                   context:nil].size;        return size.height;            } else {        //IOS7.0以下        return textView.contentSize.height;            }        return 0;}//same <pre name="code" class="objc">CGFloat fixedWidth = self.view.frame.size.width;  CGSize newSize = [label sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];  CGFloat height = newSize.height;

                                             
0 0
原创粉丝点击