gsdios / SDAutoLayout

One line of code to implement automatic layout. 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库。The most easy way for autoLayout. Based on runtime.
MIT License
5.9k stars 1.28k forks source link

如何设置一个UIView的自动宽高比? #138

Closed gentleboy closed 7 years ago

gentleboy commented 7 years ago

现在我有一个这样的布局需求,子视图距父视图顶部的间距为20,距父视图底部的间距为20,centerX与父视图相同,子视图的宽度为自身高度的一半。我写的布局代码如下:

UIView *subView = [[UIView alloc] init];
subView.backgroundColor = [UIColor redColor];
[self.view addSubview:subView];    
subView.sd_layout
.topSpaceToView(self.view,20)
.bottomSpaceToView(self.view,20)
.centerXEqualToView(self.view)
.autoHeightRatio(2);

发现不起作用,子视图不显示。我看了一下SDAutolayout的源码,并未找到设置自动宽高比的方法。求大神指点~

gsdios commented 7 years ago

目前只有高度为自身宽度的多少倍的api