gpt4 book ai didi

ios - TextView 不显示在 ScrollView 上

转载 作者:行者123 更新时间:2023-11-30 11:11:22 25 4
gpt4 key购买 nike

我有一个 View Controller 名称为 TeamDetailsViewController。我以编程方式将 ScrollView 添加到 View Controller ,并将 UITextview 添加为 ScrollView 的 subview 。但由于未知原因, TextView 没有显示。请帮忙。这是我的代码

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)
}
}

最佳答案

试试这个代码;

    var textView: UITextView = {
var tv = UITextView()
tv.textColor = .darkGray
tv.backgroundColor = .black
tv.translatesAutoresizingMaskIntoConstraints = false
tv.font = UIFont.systemFont(ofSize: 16)
return tv
}()

关于ios - TextView 不显示在 ScrollView 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52154181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com