ios - 如何在 Swift 中切换可见性 GONE 和 VISIBLE
<p><p>我想在可见性 <code>GONE</code> 和 <code>VISIBLE</code> 之间切换。
这在Android开发中确实很容易实现,但我不知道如何在<strong>Swift</strong></p>中使用相同的方法
<p>我尝试使用此代码将标签设置为消失:</p>
<pre><code>// 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)
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>隐形:</p>
<blockquote>
<p>This view is invisible, but it still takes up space for layout
purposes.</p>
</blockquote>
<p>要在 iOS 中实现:</p>
<pre><code>yourView.alpha = 0
</code></pre>
<p>走了:</p>
<blockquote>
<p>This view is invisible, and it doesn't take any space for layout
purposes.</p>
</blockquote>
<p>要在 iOS 中实现:</p>
<pre><code>yourView.removeFromSuperview()
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 Swift 中切换可见性 GONE 和 VISIBLE,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45793346/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45793346/
</a>
</p>
页:
[1]