我有一个名为TeamDetailsViewController的视图控制器。我以编程方式将滚动视图添加到视图控制器中,并将UITextview添加为滚动视图的子视图。但是由于未知的原因,文本视图没有显示出来。请帮帮忙。以下是我的代码
class TeamDetailsController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.prefersLargeTitles = false
setupViews()
}
lazy var scrollView: UIScrollView = {
let sv = UIScrollView(frame: self.view.bounds)
sv.backgroundColor = .blue
sv.autoresizingMask = UIViewAutoresizing(rawValue: UIViewAutoresizing.RawValue(UInt8(UIViewAutoresizing.flexibleWidth.rawValue) | UInt8(UIViewAutoresizing.flexibleHeight.rawValue)))
sv.contentSize = CGSize(width: self.view.bounds.size.width, height: self.view.bounds.size.height * 2);
return sv
}()
var textView: UITextView = {
var tv = UITextView()
tv.textColor = .darkGray
tv.backgroundColor = .black
tv.font = UIFont.systemFont(ofSize: 16)
return tv
}()
func setupViews() {
view.backgroundColor = .white
view.addSubview(scrollView)
scrollView.addSubview(textView)
scrollView.addConstraintsWithFormat(format: "H:|-16-[v0]-16-|", views: textView)
scrollView.addConstraintsWithFormat(format: "V:|-16-[v0]-16-|", views: textView)
}
}
https://stackoverflow.com/questions/52154181
复制相似问题