[英]Using the autolayout visual format language is it possible to set the width of a view equal to the height of the same view?
使用autolayout可視化格式語言可以將視圖的寬度設置為等於同一視圖的高度嗎?
這是我想要做的:
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[stopButton(100)]" options:kNilOptions metrics:nil views:views]];
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[stopButton(stopButton.height)" options:kNilOptions metrics:nil views:views]];
Luke Van In對固定寬高比的回答是一個很好的答案!
當然,如果您只想在多個位置使用相同的值,則可以修改代碼以使用度量字典,如下所示:
NSDictionary* metrics = @{@"stopButtonSize":@100};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[stopButton(stopButtonSize)]" options:kNilOptions metrics:metrics views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[stopButton(stopButtonSize)]" options:kNilOptions metrics:metrics views:views]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.