美文网首页iOS程序猿随笔-生活工作点滴
swift控件代码添加UIScrollView类控件

swift控件代码添加UIScrollView类控件

作者: 查理布朗Bio | 来源:发表于2019-07-11 11:12 被阅读5次

向UIViewController上代码添加UIScrollView及其子类控件时,出现内容显示超出UIScrollView的情况,此时,需要进行重新布局

override func viewDidLayoutSubviews() {
// 这里使用占满全屏的UITableView
        if #available(iOS 11.0, *) {
            let safearea = view.safeAreaInsets
            tableView.frame = CGRect(x: 0, 
                                     y: safearea.top, 
                                     width: view.bounds.width, 
                                     height: view.bounds.height-safearea.top-safearea.bottom)
        } else {
            tableView.frame = CGRect(x: 0, 
                                     y: 64,  // 非刘海屏安全距离
                                     width: view.bounds.width, 
                                     height: view.bounds.height - 64) 
        }
    }

相关文章

网友评论

    本文标题:swift控件代码添加UIScrollView类控件

    本文链接:https://www.haomeiwen.com/subject/erjrkctx.html