如何以编程方式设置纵横比限制在IOS
我已经使用了自动布局我的 ViewControllers
。我已经设定约束V和H的位置。但我想知道,如何提高我的按钮大小时,将其更改为5秒,6,6加。这是我加约束登录按钮的方式。
I have used auto layout for my ViewControllers
. I have set the V and H positions in constraints. but I want to know, How to increase my button size when it change to 5s,6 and 6 plus. This is the way I added constraints for the login button.
NSArray *btncon_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:[btnLogin(40)]" options:0 metrics:nil views:viewsDictionary];
[btnLogin addConstraints:btncon_V];
NSArray *btncon_POS_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-100-[btnLogin]-100-|" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:btncon_POS_H];
NSArray *btncon_POS_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-70-[Title]-130-[lblFirst]-0-[lblSecond]-20-[textusername]-10-[txtpassword]-10-[btnLogin]" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:btncon_POS_V];
但我的问题是,当其时管理的左右侧的差距。它越来越strched在iphone 6,6加上自thehight是固定的。我怎么能根据屏幕大小增加大小。我想这可能是 ASPECTRATIO
但是如何设置code纵横比限制。
But my problem is when when it manage the left and right side gap. Its getting strched in iphone 6 and 6 plus since thehight is fixed. How can I increase the size according to the screen size. I think this might be the AspectRatio
but how to set the aspect ratio constraint in code.
筛选。尝试一次。
[self.yourview addConstraint:[NSLayoutConstraint
constraintWithItem:self.yourview
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:self.yourview
attribute:NSLayoutAttributeWidth
multiplier:(self.yourview.frame.size.height / self.yourview.frame.size.width)
constant:0]];
或地点(self.yourview.frame.size.height / self.yourview.frame.size.width)
您可以使用任何浮点值。
谢谢你。
or in the place of (self.yourview.frame.size.height / self.yourview.frame.size.width)
you can use any float value.
Thanks.