iOS自动布局

2019-10-22 14:24:00 浏览数 (1)

简单示例

代码语言:javascript复制
override func viewDidLoad() {
   super.viewDidLoad()
   baiduMap =  BMKMapView(forAutoLayout: {}())
   self.mapView.addSubview(baiduMap);
   self.mapView.addConstraints(self.layoutConstraints())
  
}
    
func layoutConstraints() -> [NSLayoutConstraint]{
   let views = ["map": self.baiduMap ]
   let metrics = ["margin": 0]
   var result = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(margin)-[map]-(margin)-|", options:NSLayoutFormatOptions.AlignAllTop, metrics: metrics, views: views)
   result  = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(margin)-[map]-(margin)-|", options:NSLayoutFormatOptions.AlignAllLeft , metrics:metrics, views: views);
   return result
}

0 人点赞