我正在 Swift for iOS 中以編程方式布局視圖,但努力讓我的約束完全符合我的要求。這是我目前擁有的:
NSLayoutConstraint.activate([
Logo.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 30),
Logo.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -30),
Logo.heightAnchor.constraint(equalToConstant: 55),
Logo.topAnchor.constraint(equalTo: label.bottomAnchor, constant: 150),
])
這在大螢屏上很好,但隨著螢屏變小,我想關閉徽標和標簽之間的空間。目前,這被設定為 150 的固定常數。我想做的是在這里使用一個基于視圖高度(或類似的東西)的乘數,但我無法弄清楚。我應該如何定義約束來做到這一點?謝謝!
uj5u.com熱心網友回復:
你可以試試
/* Play with percent as you need also you can check current
device type iphone/ipad and set it accordingly */
let height = UIScreen.main.bounds.height * 0.25
logo.topAnchor.constraint(equalTo: label.bottomAnchor, constant: height),
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/512850.html
標籤:IOS迅速布局约束
上一篇:如何快速打開應用程式位置設定?
下一篇:如何使用手動解碼撰寫列舉
