gpt4 book ai didi

ios - 导致 textview 隐藏的约束

转载 作者:行者123 更新时间:2023-11-30 13:57:03 37 4
gpt4 key购买 nike

如果我使用文本字段,该对象将出现,但如果我使用 TextView ,该对象不会出现。我相信问题出在我的限制上?

    commentTextView.text = "test text"
commentTextView.translatesAutoresizingMaskIntoConstraints = false
commentTextView.backgroundColor = UIColor.redColor()
commentTextView.font = UIFont.boldSystemFontOfSize(bodyFontSize)
commentTextView.textColor = UIColor.whiteColor()

containerView.addSubview(commentTextView)

let views: [String : AnyObject] = [
"containerView": containerView,
"titleLabel": titleLabel,
"commentTextView": commentTextView,
"closeButton": closeButton]

view.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[containerView]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

view.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[containerView]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

containerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[titleLabel]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

containerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[commentTextView]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

containerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[closeButton]|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

containerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"V:|-(>=30)-[titleLabel]-" +
"[commentTextView]-[closeButton]-(>=10)-|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics: nil,
views: views))

任何有关让我的 TextView 出现的帮助将不胜感激

最佳答案

尝试在 TextView 上设置高度限制:

commentTextView.addConstraint(NSLayoutConstraint(item: commentTextView, 属性: .Height, relatedBy: .Equal, toItem: nil, 属性: .NotAnAttribute, 乘数: 1.0, 常量: 50.0))

文本字段无需显式设置即可知道其高度(至少使用默认边框样式)。 textview 则不然。

关于ios - 导致 textview 隐藏的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33486336/

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