开发者

set custom length and width NSWindow

开发者 https://www.devze.com 2022-12-08 21:29 出处:网络
For my application I want to set a开发者_如何学Go 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

For my application I want to set a开发者_如何学Go 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消