我想在可见性 GONE 和 VISIBLE 之间切换。
这在Android开发中确实很容易实现,但我不知道如何在Swift 中使用相同的方法
我尝试使用此代码将标签设置为消失:
// set the width constraint to 0
let widthConstraint = NSLayoutConstraint(item: self.labelShortDescription, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
self.labelShortDescription.addConstraint(widthConstraint)
// set the height constraint to 0
let heightConstraint = NSLayoutConstraint(item: self.labelShortDescription, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
self.labelShortDescription.addConstraint(heightConstraint)
Best Answer-推荐答案 strong>
隐形:
This view is invisible, but it still takes up space for layout
purposes.
要在 iOS 中实现:
yourView.alpha = 0
走了:
This view is invisible, and it doesn't take any space for layout
purposes.
要在 iOS 中实现:
yourView.removeFromSuperview()
关于ios - 如何在 Swift 中切换可见性 GONE 和 VISIBLE,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/45793346/
|