我想知道如何更改按钮的大小。
示例:处于纵向模式时的2x1按钮。处于横向模式时的1x2按钮。
我可以在故事板中使用自动布局执行此操作,还是必须以编程方式执行此操作?
答案 0 :(得分:0)
添加按钮时,只需添加
[self.view addSubView self.tableButton];
并在
- (void)viewWillLayoutSubviews {
[self.tableConstraintWidth autoRemove];
[self.tableConstraintLeft autoRemove];
[self.tableConstraintHeight autoRemove];
[self.tableConstraintTop autoRemove];
//Assign again with different constraints depending on the orientation
Check orientation
if(Landscape) {
self.tableConstraintLeft = Left constraint
self.tableConstraintTop = Top Constraint
self.tableConstraintWidth = Width Constraint
self.tableConstraintHeight = Height Constraint
}else {
self.tableConstraintLeft = Left constraint
self.tableConstraintTop = Top Constraint
self.tableConstraintWidth = Width Constraint
self.tableConstraintHeight = Height Constraint
}
}