根据变量迅速调整窗口大小 [英] Resizing the window according to a variable swift
本文介绍了根据变量迅速调整窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NSViewController
和一个变量num
.我想根据该变量动态更改窗口的大小.有什么办法可以迅速做到这一点?
I have a NSViewController
and a variable num
. I want to change the size of the window dynamically according to that variable. Is there any way to do that in swift?
推荐答案
比方说,您的窗口有一个名为"window"的IBOutlet,而您的动态编号为"myDynamicNumber":
Let's say your window has an IBOutlet named "window", and your dynamic number is named "myDynamicNumber":
func resize() {
var windowFrame = window.frame
let oldWidth = windowFrame.size.width
let oldHeight = windowFrame.size.height
let toAdd = CGFloat(myDynamicNumber)
let newWidth = oldWidth + toAdd
let newHeight = oldHeight + toAdd
windowFrame.size = NSMakeSize(newWidth, newHeight)
window.setFrame(windowFrame, display: true)
}
这篇关于根据变量迅速调整窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文