频道栏目
首页 > 资讯 > IOS > 正文

IOS开发之uitextview动态适应高度讲解

18-07-21        来源:[db:作者]  
收藏   我要投稿

IOS开发之uitextview动态适应高度讲解

1. 

self.tableView.rowHeight = UITableViewAutomaticDimension;

    self.tableView.estimatedRowHeight = 44;

2. 在heightForRowAtIndexPath中设置return UITableViewAutomaticDimension;

3. 

- (void)textViewDidChange:(UITextView *)textView {

    CGRect bounds = textView.bounds;

    //     计算 text view 的高度

    CGSize maxSize = CGSizeMake(bounds.size.width, CGFLOAT_MAX);

    CGSize newSize = [textView sizeThatFits:maxSize];

    bounds.size = newSize;

    textView.bounds = bounds;

    // 让 table view 重新计算高度

    //2.textView的高度不想等就更新 让 table view 重新计算高度

    if (bounds.size.height != self.contentView.bounds.size.height) {

        UITableView *tableView = [self tableView];

        [tableView beginUpdates];

        [tableView endUpdates];

    }

    self.contentView.bounds = bounds;

}

- (UITableView *)tableView {

    UIView *tableView = self.superview;

    while (![tableView isKindOfClass:[UITableView class]] && tableView) {

        tableView = tableView.superview;

    }

    return (UITableView *)tableView;

}
相关TAG标签
上一篇:GitHub简单的注册、安装及使用
下一篇:go语言之面向对象,结构体和方法学习
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站