我想制作一个这样的关闭按钮,
收缩
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[btnClose(==10)]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:NSDictionaryOfVariableBindings(btnClose)]];
消失,错误
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[btnClose(==-10)]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:NSDictionaryOfVariableBindings(btnClose)]];
我应该采用什么约束来在所有设备中支持关闭按钮,如图所示。?
答案 0 :(得分:0)
您应该提供水平和垂直约束(如果10和0是顶部和右侧的空格):
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[btnClose]-0-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(btnClose)]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[btnClose]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(btnClose)]];
您无需指定按钮的尺寸 - 它们将从内容推断出来,在您的情况下图像尺寸