&#34,V:| [V(大于=高度)] - 0.0@highPriority-|"
对于VFL以上的约束(NSLayoutConstraint样式)。
也许正在考虑使用greaterThanEqual
&使用UILayoutPriority.defaultHigh
的底部约束。
我用过的东西 -
let heightConstraint = NSLayoutConstraint(item: self.view!, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.greaterThanOrEqual, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.view!, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0)
bottomConstraint.priority = .defaultHigh
NSLayoutConstraint.activate([heightConstraint,bottomConstraint])
答案 0 :(得分:0)
初步设置答案:
<ListView
stickySectionHeadersEnabled={false}
scrollEnabled={!this.state.shouldAnimate}
style={styles.listView}
enableEmptySections={true}
dataSource={this.state.dataSource}
renderSectionHeader = {this.renderSectionHeader}
renderRow={(data,i) => {
if(i==1){}
else if (i==2){}
.......
}}
/>
对于给定的VFL:
&#34,V:| [V(大于=高度)] - 0.0@highPriority-|"
let parentView = self.view!
let childView = UIView()
childView.backgroundColor = UIColor.lightGray
childView.translatesAutoresizingMaskIntoConstraints = false
parentView.addSubview(childView)
上述VFL的let height: CGFloat = 100
let priority: Int = 1000
//VFL (for vertical positioning and height of childView
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v(>=\(height))]-0.0@\(priority)-|",
options: [],
metrics: nil,
views: ["v" : childView]))
等效词是:
NSLayoutConstraint
注意:问题中给定的VFL仅提供let height: CGFloat = 100
//VFL Equivalent: "V:|[v]"
let topConstraint = NSLayoutConstraint(item: childView,
attribute: .top,
relatedBy: .equal,
toItem: parentView,
attribute: .top,
multiplier: 1,
constant: 0)
//VFL Equivalent: "[v(>=height)]"
let heightConstraint = NSLayoutConstraint(item: childView,
attribute: .height,
relatedBy: .greaterThanOrEqual,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1,
constant: height)
//VFL Equivalent: "[v]|" or "[v]-0.0-|"
let bottomConstraint = NSLayoutConstraint(item: childView,
attribute: .bottom,
relatedBy: .equal,
toItem: parentView,
attribute: .bottom,
multiplier: 1,
constant: 0)
//Adding VFL Equivalent: @priority
bottomConstraint.priority = .defaultHigh
childView.addConstraint(heightConstraint)
parentView.addConstraint(topConstraint)
parentView.addConstraint(bottomConstraint)
的位置和高度
对于width,请相应地添加约束。
宽度的VFL示例为:
childView
参考: