如何以编程方式设置纵横比限制在IOS [英] How to set aspect ratio constraint programmatically in ios

查看:129
本文介绍了如何以编程方式设置纵横比限制在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.

这篇关于如何以编程方式设置纵横比限制在IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆