2016-08-18 24 views
-1

我不想讓IBOutlet的視圖和頂部佈局指南之間的約束。我不想把標識符也。我想以編程方式找到它。任何人都請幫助我。如何查看視圖和頂部佈局指南之間的約束?

+0

問題是否解決? –

+0

是的我設法通過遍歷視圖的所有約束,並檢查它是否滿足條件來解決它(約束。首先作爲?NSObject == self.view && constraint.firstAttribute ==。頂端)|| (constraint.secondItem as?NSObject == self.view && constraint.secondAttribute == .Top) – sant05

回答

0

這就是你如何以編程方式聲明約束。請找到代碼片段。

let view = UIView()  
let leadingConstraint = view.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor) 
let trailingConstraint = view.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor) 
let topConstraint = view.topAnchor.constraintEqualToAnchor(self.view.topAnchor) 
let bottomConstraint = view.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor, constant: 0) 
var setConstraints = [NSLayoutConstraint]() 
setConstraints.appendContentsOf([leadingConstraint,trailingConstraint,topConstraint,bottomConstraint])  
NSLayoutConstraint.activateConstraints(setConstraints) 

請勾選是否有幫助。

謝謝。

+0

我想找到我從Interface Builder添加的約束條件。 – sant05

1

選擇constraint並添加identifier「TopLayOut就像在下面的PIC添加:通過限制

enter image description here

,並在你的代碼進行迭代,並找到如下正確的:

for constraint in self.view.constraints{ 

      if constraint == "TopLayOut"{ 
       print("matches") 
       break; 
      } 
    } 
+0

感謝您的回答。其實我需要找到它,而不用把標識符也。 – sant05

相關問題