简体   繁体   English

如何使用自动布局更改按钮的大小?

[英]How do I change button's size with Auto-layout?

I was wondering how I can change a button's size. 我想知道如何更改按钮的大小。

Example: 2x1 button when in portrait mode. 示例:在纵向模式下使用2x1按钮。 1x2 button when in landscape mode. 在横向模式下使用1x2按钮。

Can I do this in storyboard with autolayout or do I have to do this programmatically? 我可以使用自动布局在情节提要中执行此操作,还是必须以编程方式执行此操作?

While adding button,just add 添加按钮时,只需添加

[self.view addSubView self.tableButton];

and in 和在

- (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

 }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM