Open popeyelau opened 5 years ago
class Device { // 以 iPhone 6 尺寸为设计稿 static let base: CGFloat = 375 static var ratio: CGFloat { return UIScreen.main.bounds.width / base } } xtension CGFloat { var adjusted: CGFloat { return self * Device.ratio } } extension Double { var adjusted: CGFloat { return CGFloat(self) * Device.ratio } } extension Int { var adjusted: CGFloat { return CGFloat(self) * Device.ratio } }
label.font = UIFont.systemFont(ofSize: 23.adjusted) phoneTextField.leftAnchor.constraint(equalTo: container.leftAnchor, constant: 30.adjusted) phoneTextField.rightAnchor.constraint(equalTo: container.rightAnchor, constant: -30.adjusted) imageView.widthAnchor.constraint(equalToConstant: 80.adjusted) imageView.heightAnchor.constraint(equalToConstant: 90.adjusted)
How to handle Auto Layout with different screen sizes
How to handle Auto Layout with different screen sizes