我正在尝试使用 VFL(视觉格式语言)创建具有以下布局的视图
------------------------------------------------- | [左视图] [中心视图] [右视图]| -------------------------------------------------
但它是这样出现的
------------------------------------------------- | [左视图] [右视图]| -------------------------------------------------
我认为问题出在这条线上
H:|-10-[cancel(70)]-[title]-[save(70)]-10-|
这是其余的代码,我不知道我做错了什么。这是我的代码:
let headerView = UIView(frame: CGRectMake(0,0,mainFrame.width, headerHeight))
headerView.backgroundColor = BG_COLOR
self.addSubview(headerView)
let cancelButton = UIButton(type: .Custom)
cancelButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.setTitle("Cancel", forState: .Normal)
cancelButton.addTarget(self, action: "cancelButtonClick:", forControlEvents: .TouchUpInside)
headerView.addSubview(cancelButton)
let titleLabel = UILabel()
titleLabel.text = "Bedroom"
titleLabel.textColor = UIColor.whiteColor()
headerView.addSubview(titleLabel)
let saveButton = UIButton(type: .Custom)
saveButton.titleLabel?.textAlignment = NSTextAlignment.Right
saveButton.translatesAutoresizingMaskIntoConstraints = false
saveButton.setTitle("Save", forState: .Normal)
saveButton.addTarget(self, action: "saveButtonClick:", forControlEvents: .TouchUpInside)
headerView.addSubview(saveButton)
let views = ["title":titleLabel, "cancel":cancelButton,"save":saveButton,"header":headerView]
headerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[save]|",
options:[.AlignAllCenterY],
metrics:nil,
views:views)
)
headerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[cancel]|",
options:[.AlignAllCenterY],
metrics:nil,
views:views)
)
headerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[title]|",
options:[.AlignAllCenterY],
metrics:nil,
views:views)
)
headerView.addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat(
"H:|-10-[cancel(70)]-[title]-[save(70)]-10-|",
options:[.AlignAllCenterY],
metrics:nil,
views:views)
)