<small id='KwMG2'></small><noframes id='KwMG2'>

    <bdo id='KwMG2'></bdo><ul id='KwMG2'></ul>
  • <i id='KwMG2'><tr id='KwMG2'><dt id='KwMG2'><q id='KwMG2'><span id='KwMG2'><b id='KwMG2'><form id='KwMG2'><ins id='KwMG2'></ins><ul id='KwMG2'></ul><sub id='KwMG2'></sub></form><legend id='KwMG2'></legend><bdo id='KwMG2'><pre id='KwMG2'><center id='KwMG2'></center></pre></bdo></b><th id='KwMG2'></th></span></q></dt></tr></i><div id='KwMG2'><tfoot id='KwMG2'></tfoot><dl id='KwMG2'><fieldset id='KwMG2'></fieldset></dl></div>
  • <tfoot id='KwMG2'></tfoot>

  • <legend id='KwMG2'><style id='KwMG2'><dir id='KwMG2'><q id='KwMG2'></q></dir></style></legend>

        如何在 Xcode 游乐场中使用自动布局约束显示视图?

        时间:2023-09-10
      1. <small id='TxNLY'></small><noframes id='TxNLY'>

        <legend id='TxNLY'><style id='TxNLY'><dir id='TxNLY'><q id='TxNLY'></q></dir></style></legend>

              <bdo id='TxNLY'></bdo><ul id='TxNLY'></ul>

              <i id='TxNLY'><tr id='TxNLY'><dt id='TxNLY'><q id='TxNLY'><span id='TxNLY'><b id='TxNLY'><form id='TxNLY'><ins id='TxNLY'></ins><ul id='TxNLY'></ul><sub id='TxNLY'></sub></form><legend id='TxNLY'></legend><bdo id='TxNLY'><pre id='TxNLY'><center id='TxNLY'></center></pre></bdo></b><th id='TxNLY'></th></span></q></dt></tr></i><div id='TxNLY'><tfoot id='TxNLY'></tfoot><dl id='TxNLY'><fieldset id='TxNLY'></fieldset></dl></div>
              <tfoot id='TxNLY'></tfoot>
                <tbody id='TxNLY'></tbody>

                1. 本文介绍了如何在 Xcode 游乐场中使用自动布局约束显示视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在 XCode playground 中显示配置有 autolayout 约束的视图,但它似乎不起作用.就像游乐场完全忽略了约束,我在任何地方都找不到有关此问题的信息.

                  I am trying to display views configured with autolayout constraints in XCode playground, but it doesn't seem to work. It's like playground ignores the constraints completely, and I can't find information about this issue anywhere.

                  这是我尝试过的代码:

                  let view = UIView()
                  view.frame = CGRectMake(0, 0, 400, 200)
                  view.backgroundColor = UIColor.lightGrayColor()
                  
                  let label = UILabel() // I can only see the label if I set a frame
                           // UILabel(frame: CGRectMake(0, 0, 200, 50))
                  label.backgroundColor = UIColor.greenColor()
                  label.text = "I am a label"
                  label.setTranslatesAutoresizingMaskIntoConstraints(false)
                  view.addSubview(label)
                  
                  let views = ["label":label]
                  let options = NSLayoutFormatOptions(0)
                  
                  let cs1 = NSLayoutConstraint.constraintsWithVisualFormat(
                      "H:|-[label]-|", options: options, metrics: nil, views:views )
                  
                  let cs2 = NSLayoutConstraint.constraintsWithVisualFormat(
                      "V:|-[label]-|", options: options, metrics: nil, views:views )
                  
                  view.addConstraints(cs1)
                  view.addConstraints(cs2)
                  

                  提前致谢

                  推荐答案

                  也就是说你可以使用 PlaygroundPageliveView 属性来预览你的 UI.

                  That being said you can use the liveView property of PlaygroundPage to preview your UI.

                  import PlaygroundSupport
                  
                  PlaygroundPage.current.needsIndefiniteExecution = true
                  PlaygroundPage.current.liveView = myLiveView
                  

                  这是一个进一步扩展的 链接.

                  Here's a link that expands on this further.

                  如果它不起作用,您可能需要触发 layoutIfNeeded 但这不应该真正解决问题,因为 Swift 4

                  If its not working you may need to trigger a layoutIfNeeded but that shouldn't really solve the issue since Swift 4

                  另外,在您的视图中包含 translatesAutoresizingMaskIntoConstraints = false.喜欢:

                  Also, include translatesAutoresizingMaskIntoConstraints = false on your view. Like:

                  import PlaygroundSupport
                  
                  myLiveView.translatesAutoresizingMaskIntoConstraints = false
                  PlaygroundPage.current.needsIndefiniteExecution = true
                  PlaygroundPage.current.liveView = myLiveView
                  

                  这篇关于如何在 Xcode 游乐场中使用自动布局约束显示视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Stackview 交换或更改视图顺序 下一篇:UIView 纵横比混淆 systemLayoutSizeFittingSize

                  相关文章

                  <i id='CGyqF'><tr id='CGyqF'><dt id='CGyqF'><q id='CGyqF'><span id='CGyqF'><b id='CGyqF'><form id='CGyqF'><ins id='CGyqF'></ins><ul id='CGyqF'></ul><sub id='CGyqF'></sub></form><legend id='CGyqF'></legend><bdo id='CGyqF'><pre id='CGyqF'><center id='CGyqF'></center></pre></bdo></b><th id='CGyqF'></th></span></q></dt></tr></i><div id='CGyqF'><tfoot id='CGyqF'></tfoot><dl id='CGyqF'><fieldset id='CGyqF'></fieldset></dl></div>

                      <small id='CGyqF'></small><noframes id='CGyqF'>

                      • <bdo id='CGyqF'></bdo><ul id='CGyqF'></ul>
                    1. <tfoot id='CGyqF'></tfoot>
                    2. <legend id='CGyqF'><style id='CGyqF'><dir id='CGyqF'><q id='CGyqF'></q></dir></style></legend>