OGeek|极客世界-中国程序员成长平台

标题: ios - 我们如何在 Storyboard 中动态设置 NSLayoutConstraint 值 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:01
标题: ios - 我们如何在 Storyboard 中动态设置 NSLayoutConstraint 值

我们能否在 Storyboard 中为不同的 iOS 设备动态设置 NSLayoutConstraint 的值。

    @IBOutlet var topnIconCnst: NSLayoutConstraint!

    if DeviceType.IS_IPHONE_4_OR_LESS {
        topnIconCnst.constant = 20
    }
    else if  DeviceType.IS_IPHONE_5 {
        topnIconCnst.constant = 60
    }
    else if  DeviceType.IS_IPHONE_6 {
        topnIconCnst.constant = 70
 }



Best Answer-推荐答案


在设置新的约束值后尝试调用 self.view.layoutIfNeeded()

关于ios - 我们如何在 Storyboard 中动态设置 NSLayoutConstraint 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40530637/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4