Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing the window according to a variable swift

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?

like image 636
pomo_mondreganto Avatar asked Mar 23 '15 07:03

pomo_mondreganto


2 Answers

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)
}
like image 98
Eric Aya Avatar answered Sep 19 '22 04:09

Eric Aya


In Swift 3 to resize the window you use setFrame.

An example from the ViewController:

func resizeWin(size:(CGFloat,CGFloat)){

    self.view.window?.setFrame(NSRect(x:0,y:0,width:size.0,height:size.1), display: true)

}
like image 25
melMass Avatar answered Sep 19 '22 04:09

melMass