我有一个正在使用Xcode 9.2和Swift4的iOS项目。我有一个UITextView,但第二个UITextView不可见。

let logo: UIImageView = {
    let imageView = UIImageView(image: #imageLiteral(resourceName: "logoyeni"));
    imageView.translatesAutoresizingMaskIntoConstraints = false
    return imageView
}()

let bannerText: UITextView = {
   let textView = UITextView()
    textView.text = "Müziğin Sosyal Medyası";
    textView.textColor = UIColor.salmon;
    textView.textAlignment = .center
    textView.isEditable = false
    textView.translatesAutoresizingMaskIntoConstraints = false
    textView.isScrollEnabled = false
    return textView
}()

let slogan: UITextView = {
    let textView1 = UITextView()
    textView1.text = "Lorem Ipsum Dolor Sit Amet Consectetur";
    //textView.font = UIFont.textStyle3;
    //textView.textColor = UIColor.cloudyBlue;
    textView1.textAlignment = .center;
    textView1.isEditable = false
    textView1.translatesAutoresizingMaskIntoConstraints = false;
    return textView1
}()

ViewDidLoad =
    super.viewDidLoad()

    view.addSubview(logo);
    view.addSubview(bannerText);
    view.addSubview(slogan);
    setup();

和约束=
private func setup(){
    logo.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    logo.topAnchor.constraint(equalTo: view.topAnchor, constant: 100).isActive = true
    logo.widthAnchor.constraint(equalToConstant: 127).isActive = true
    logo.heightAnchor.constraint(equalToConstant: 127).isActive = true

    bannerText.topAnchor.constraint(equalTo: logo.bottomAnchor, constant: 29).isActive = true
    bannerText.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    bannerText.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    bannerText.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true

    slogan.topAnchor.constraint(equalTo: bannerText.bottomAnchor, constant: 4).isActive = true
    slogan.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    slogan.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
    slogan.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
}

如何解决这个问题?

最佳答案

您的约束是错误的。
bannerText.bottomAnchor = view.bottomAnchorslogan.topAnchor = bannerText.bottomAnchor(view.bottomAnchor)slogan.bottomAnchor = view.bottomAnchor
这会将第二个文本视图的高度设置为零。
您应该对至少一个文本视图设置高度限制,而不是将两个视图都固定在superView的底部。

关于ios - 快速第二个textview不可见,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48245158/

10-09 16:13