Question

For my application I want to set a custom length and width for my NSWindow from within the application itself. I have everything set up (the NSTextfields) however I'm stumped with how I should do it.

Was it helpful?

Solution

NSRect is defined like this:

typedef struct _NSRect {
    NSPoint origin;
    NSSize size;
} NSRect;

And NSSize is defined like this:

typedef struct _NSSize {
    CGFloat width;
    CGFloat height;
} NSSize;

You need to convert your NSStrings to numbers first. You can do that like this:

CGFloat numericalValue = [stringValue doubleValue];

(I don't actually remember if CGFloat is defined as a float or double. I'm just too lazy to look it up right now.) Note that this will cause an exception if stringValue does not represent a properly formatted number.

OTHER TIPS

You want the setFrame:display: or setFrame:display:animate: method on NSWindow.

From the documentation:

- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews

Parameters
windowFrame
The frame rectangle for the window.

displayViews
Specifies whether the window redraws the views that need to be displayed. When YES the window sends a displayIfNeeded message down its view hierarchy, thus redrawing all views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top