SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout
MIT License
18.05k stars 3.14k forks source link

怎么约束最大高度 #494

Open OCer opened 6 years ago

OCer commented 6 years ago

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

Issue Info

Info Value
Platform ios
Platform Version 9.0
Masonry Version 1.1
Integration Method manually

Issue Description

[make height].equalTo([self mas_width]).multipliedBy(1.777f); [make height].lessThanOrEqualTo(self).priorityHigh();

我想要的结果,height的值是self width的1.777倍,并且最大值只能和self height一样 也就是说,如果self的宽度*1.777大于self height的时候,高度就是height 但实际上,我发现我的设置好像并没有用,我也尝试过不同的优先级设置,并不行 希望有大神帮解下惑,先谢谢各位大佬了

lichory commented 6 years ago

[make height].equalTo([self mas_width]).multipliedBy(1.777f); 这个权限可以变低点了

OriTheElf commented 6 years ago

可以使用不等关系lessThanOrEqualTo

OCer commented 6 years ago

并不行 如果equalTo权限比lessThanOrEqualTo权限低 那么总是lessThanOrEqualTo生效,然后[make height].equalTo([self mas_width]).multipliedBy(1.777f);就没办法约束比例关系,因为这句不生效 如果equalTo权限比lessThanOrEqualTo权限高 那么lessThanOrEqualTo无效,这就意味着高度会超出范围 @lichory @OrisForest

dongpoRen commented 6 years ago

[make height].equalTo([self mas_width]).multipliedBy(1.777f).priorityHigh(); [make height].lessThanOrEqualTo(self);

ChoshimWy commented 8 months ago

label.translatesAutoresizingMaskIntoConstraints = false label.widthAnchor.constraint(lessThanOrEqualToConstant: 120).isActive = true

You can use the maximum value set by the system widthAnchor。