我無法找到在Interface Builder中創建'square'約束的方法,意思是'width equals height'。我想可以通過編程添加這樣的約束。 IB有什麼我可以做的嗎?也許我只是看不到它?這似乎微不足道,但我找不到它。Interface Builder中的「Width equal height」約束
回答
更新的Xcode 5.1b5
Ctrl +單擊並從視圖中拖動和釋放,而指針所在的視圖。選擇「長寬比」。它會在第一個和第二個項目是視圖時創建一個約束。
的Xcode 5.1
之前不能因爲寬度/高度編輯缺乏領域涉及到另一個屬性或設置的比率:
因此,您不能在Interface Builder中表示以下代碼:
CGFloat ratio = 1.0;
NSLayoutConstraint *constraint = [NSLayoutConstraint
constraintWithItem:myView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:myView
attribute:NSLayoutAttributeHeight
multiplier:ratio
constant:0];
constraint.priority = 1000;
[myView.superview addConstraint:constraint];
感謝您的最新更新。 Xcode 5.1 beta 5實際上允許您在IB中設置寬高比約束,但是當我嘗試編譯項目時,出現以下錯誤:使用5.1之前的Xcode版本時的_Aspect比率限制。所以也許我們必須等待最後的5.1版本。你也一樣@Jano? – 2014-02-10 16:32:30
是的,對XIB的更改不向後兼容。如果你用5.1編輯,你不能回到較小的版本。 – Jano 2014-02-10 17:37:14
所以你可以編譯xib?即使對於我來說Xcode 5.1 beta 5也不行。 – 2014-02-10 23:22:22
- 1. JS「Window」width-height vs「screen」width-height?
- 2. 力量倍增器來更新Interface Builder的約束
- 3. 爲UIScrollView的約束誤差在Interface Builder空UIStackView
- 4. 與Interface Builder中
- 5. Interface Builder中的UIDatePicker
- 6. Interface Builder縮放?
- 7. 沒有Interface Builder中
- 8. TImage width/height anchor not working
- 9. ImageButton:Force square icon(height = WRAP_CONTENT,width =?)
- 10. Interface Builder中的組視圖
- 11. 的Xcode,Interface Builder中和StackView
- 12. Interface Builder錯誤?
- 13. Interface Builder + Sprite Strips
- 14. NSOpenGLView沒有Interface Builder中
- 15. 從Shadertoy在Interface Builder(Xcode中)
- 16. 使用jQuery的width()和height()方法
- 17. jQuery .width()和.height()奇怪的行爲
- 18. Xcode/Interface Builder崩潰
- 19. Interface Builder崩潰(iOSRenderServer)
- 20. Interface Builder中的UITabBar - 太髒了?
- 21. 沒有iOS中的Interface Builder中的IBOutlets
- 22. Interface Builder的隱藏功能?
- 23. 的UIView layoutMargins在Interface Builder
- 24. NSAttributedString height由width和numberOfLines限制
- 25. Jquery; Chrome Image Width and Height = 0 for new Image()
- 26. 圖不服從width和height屬性
- 27. iOS獲得對Interface Builder中添加的特定自動佈局約束的引用,代碼爲
- 28. 使用Xcode 4.2的Interface Builder中的UIApplicationDelegate
- 29. UITableViewCell的contentView獲取不需要的「height == 44」約束
- 30. 在Interface Builder中查找連接的IBAction
我記得Peter Ammon在WWDC'12中討論了「儘可能依賴Interface Builder」。多麼諷刺。 – DemoniacDeath 2013-03-02 23:41:25
是的,我認爲佈局約束的實現還有一些缺失。看起來他們已經讓我們獲得了大部分參數,但不是乘數,這對於很多事情都是有用的。 – rdelmar 2013-03-03 00:40:41
但它越來越好!我的意思是自動佈局不到3年前推出,從我的角度來看,現在的支持非常好。 – 2014-02-10 16:37:00