简体   繁体   English

快速第二个textview不可见

[英]swift second textview not visible

I have an iOS project I'm working on using Xcode 9.2 and Swift4. 我有一个正在使用Xcode 9.2和Swift4的iOS项目。 I have a UITextView but second the UITextView not visible. 我有一个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 = ViewDidLoad =

    super.viewDidLoad()

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

and constrains = 和约束=

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
}

How to fix this problem? 如何解决这个问题?

屏幕

Your constraints are wrong. 您的约束是错误的。

bannerText.bottomAnchor = view.bottomAnchor

slogan.topAnchor = bannerText.bottomAnchor(view.bottomAnchor)

slogan.bottomAnchor = view.bottomAnchor

This will set the height of the second text view to zero. 这会将第二个文本视图的高度设置为零。 You should have a height constraint for at least one of the text views rather than pinning both of them to the bottom of the superView. 您应该对至少一个文本视图设置高度限制,而不是将两个视图都固定在superView的底部。

You have pinned the bannerText to the bottom of the logo (offset by 29) and the left, right and bottom of the view. 您已将bannerText固定在徽标的底部(偏移29)和视图的左侧,右侧和底部。

You have then pinned the slogan to the bottom of the bannerText (offset by 4) and the left, right and bottom of the view. 然后,您已将标语固定在bannerText的底部(偏移量为4)以及视图的左,右和底部。

That's not going to work because the bottom of the bannerText and the bottom of the view are the same and as the top of the slogan is the bottom of the view the top of slogan ends up being the bottom of the view and therefore it is outside the view (the constraints probably break as well). 这是行不通的,因为bannerText的底部和视图的底部是相同的,并且标语的顶部是视图的底部,标语的顶部最终是视图的底部,因此它在外部视图(约束也可能会破裂)。

You need to fix the constraints based on what you want to see. 您需要根据要查看的内容修复约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM