gpt4 book ai didi

uiview - 如何更改 UIView 大小?

转载 作者:IT王子 更新时间:2023-10-29 04:58:45 30 4
gpt4 key购买 nike

我无法在启动时修改我的 UIView 高度。

我必须使用 UIView,我希望其中一个屏幕大小 * 70,另一个填补空白。

这是我的

 @IBOutlet weak var questionFrame: UIView!
@IBOutlet weak var answerFrame: UIView!
let screenSize:CGRect = UIScreen.mainScreen().bounds

 questionFrame.frame.size.height = screenSize.height * 0.70
answerFrame.frame.size.height = screenSize.height * 0.30

它在运行时对应用程序没有影响。我使用自动布局,但我只有边距限制...

我做错了吗?

最佳答案

这可以通过 Swift 3.0 中的各种方法实现 在 MAY-2019 的最新版本上工作

直接为 View 分配高度和宽度值:

userView.frame.size.height = 0

userView.frame.size.width = 10

为框架分配 CGRect

userView.frame =  CGRect(x:0, y: 0, width:0, height:0)

方法详情:

CGRect(x: point of X, y: point of Y, width: Width of View, height: Height of View)

使用 CGRECT 的扩展方法

在任意swift文件中添加如下扩展代码,

extension CGRect {

init(_ x:CGFloat, _ y:CGFloat, _ w:CGFloat, _ h:CGFloat) {

self.init(x:x, y:y, width:w, height:h)
}
}

在您的应用程序的任何位置使用以下代码为 View 设置尺寸参数

userView.frame =  CGRect(1, 1, 20, 45)

关于uiview - 如何更改 UIView 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26706565/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com