自动布局TextView NSLayoutConstraint中的Swift未更改,TextView动态的高度更改
我对自动布局一无所知,因为我有一个UITextView,高度为115,宽度为320,如果我在数组中有一些图像,那么我将textview高度设置为50到60,并在下面显示textview的图像,我尝试设置为NSLayoutConstraint,但我无法更改textview的高度。 请给我答案,这是我的代码 首先我试试这个自动布局TextView NSLayoutConstraint中的Swift未更改,TextView动态的高度更改,swift,autolayout,constraints,Swift,Autolayout,Constraints,我对自动布局一无所知,因为我有一个UITextView,高度为115,宽度为320,如果我在数组中有一些图像,那么我将textview高度设置为50到60,并在下面显示textview的图像,我尝试设置为NSLayoutConstraint,但我无法更改textview的高度。 请给我答案,这是我的代码 首先我试试这个 @IBOutlet var txt_description: UITextView! override func viewWillAppear(animated: Bo
@IBOutlet var txt_description: UITextView!
override func viewWillAppear(animated: Bool) {
self.view.addConstraint(NSLayoutConstraint(item: txt_description, attribute: .Top, relatedBy: .Equal, toItem: view_of_segment, attribute: .Top, multiplier: 1, constant:10))
}
二是
override func viewWillAppear(animated: Bool) {
NSLayoutConstraint.activateConstraints([
NSLayoutConstraint(item: txt_description, attribute: .Top, relatedBy: .Equal, toItem: txt_title, attribute: .Top, multiplier: 1.0, constant: 24),
NSLayoutConstraint(item: txt_description, attribute: .Left, relatedBy: .Equal, toItem: txt_title, attribute: .Left, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: txt_description, attribute: .Width, relatedBy: .Equal, toItem: txt_title, attribute: .Width, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: txt_description, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant:4)
])
}
第三,我试试这个
@IBOutlet var EqualHeight_txt_des: NSLayoutConstraint!
@IBOutlet var txt_description: UITextView!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
let leftiPadWidth:CGFloat = 50
txt_description.setTranslatesAutoresizingMaskIntoConstraints(false)
EqualHeight_txt_des.constant = leftiPadWidth
}
请给我答案
我无法更改文本视图高度
请分享你的宝贵知识