你如何设置UILayoutPriority?

时间:2018-03-15 12:53:24

标签: ios swift autolayout nslayoutconstraint

我尝试创建对约束的引用,然后设置布局优先级,但这会导致应用程序崩溃

let topTrasactionConstraint = transactionsTableviewContainer.topAnchor.constraint(equalTo: buttonsStackContainerView.bottomAnchor, constant: 6)


    NSLayoutConstraint.activate([
            topTrasactionConstraint,
            transactionsTableviewContainer.centerXAnchor.constraint(equalTo: contentView.centerXAnchor),
            transactionsTableviewContainer.widthAnchor.constraint(equalTo: contentView.safeAreaLayoutGuide.widthAnchor, constant: -20),
            transactionsTableviewContainer.heightAnchor.constraint(equalToConstant: 500)
            ])


topTrasactionConstraint.priority = UILayoutPriority.init(999)

2 个答案:

答案 0 :(得分:3)

我发现我正在打电话

topTrasactionConstraint.priority = UILayoutPriority.init(999)

NSLayoutConstraint.activate之前 这导致我的应用程序崩溃

答案 1 :(得分:0)

<!DOCTYPE html> <html> <title>W3.CSS</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <body> <form action="/action_page.php" class="w3-container w3-card-4 w3-light-grey w3-text-blue w3-margin"> <h2 class="w3-center">Dg Ebook</h2> <div class="w3-row w3-section"> <div class="w3-col" style="width:50px"><i class="w3-xxlarge fa fa-envelope-o"></i></div> <div class="w3-rest"> <input class="w3-input w3-border" name="email" type="text" placeholder="Enter Your Best Email"> </div> </div> <button class="w3-button w3-block w3-section w3-blue w3-ripple w3-padding">Send me The FREE eBook on Email</button> </form> </body> </html>怎么样?

https://useyourloaf.com/blog/easier-swift-layout-priorities/