2017-07-10 42 views
0

我正在編寫一個應用程序,我想知道如何將視圖錨定到底部而不是前一視圖的右側,當同一行中的總寬度超過設備寬度。Swift 3如何在超過寬度時錨定底部

基本上是這樣的:

View 1: width=150 anchor to superview's leftAnchor 
View 2: width=500 anchor to view1's rightAnchor 
View 3: width=1000 anchor to view1's bottomAnchor because total width in same row 
exceeds device width 

#device width=1200 

任何幫助理解。對不起,英語不好,不是母語。

Ps。所有的高度都是一樣的,寬度是動態的

回答

0

主要的挑戰是我不知道我的意見的寬度,直到他們受到限制。

所以我用swift的估計。

let size = CGSize(width: UIScreen.main.bounds.width, height: 50) 
let attributeHeight = [NSFontAttributeName: UIFont.preferredFont(forTextStyle: .subheadline)] 
let estimatedHeight = NSString(string: _title).boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributeHeight, context: nil) 
self._estimatedWidth = estimatedHeight.width + 32 

後很容易根據我的使用需求環

錨他們