iOS自动布局 发表于 2015-10-22 | 分类于 ios iOS自动布局 简单示例123456789101112131415override 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}