Custom NSView with NSTextField

So, I draw a custom window (transparent) using a custom NSView as the content content, and would like to add an NSTextField to the window, however, when I add an NSTextField, I get a weird resizing or redrawing of a custom NSView, and I can't figure out what causes a problem. Window and window contents are subclasses of NSWindow and NSView respectively. In addition, I tried to simply fold the custom NSView (do not set it as a contentview) without changes. Any ideas?

    NSWindow *quickEntryWindow = [[TransparentWindow alloc] initWithContentRect:NSMakeRect([[NSScreen mainScreen] frame].size.width/2 - 250, [[NSScreen mainScreen] frame].size.height/2 + 50, 500, 100) 
                                                            styleMask:NSBorderlessWindowMask
                                                              backing:NSBackingStoreBuffered 
                                                                defer:NO
                                                              special:YES];
    BorderView *quickEntryBorderView = [[BorderView alloc] initWithFrame:NSMakeRect(0, 0, [[quickEntryWindow contentView] frame].size.width, [[quickEntryWindow contentView] frame].size.height)];
    [quickEntryBorderView canDrawConcurrently];
    [quickEntryWindow setContentView:quickEntryBorderView];
    NSTextField *quickEntryTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, [quickEntryBorderView frame].size.width-20, [quickEntryBorderView frame].size.height-20)];
    [quickEntryTextField setAutoresizingMask:NSViewNotSizable];
    [quickEntryTextField setBordered:NO];
    [quickEntryTextField setDrawsBackground:NO];
    [quickEntryTextField setFocusRingType:NSFocusRingTypeNone];
    [quickEntryTextField setFont:[NSFont fontWithName:@"Helvetica" size:42]];
    [quickEntryTextField setTextColor:[NSColor grayColor]];
    [quickEntryBorderView addSubview:quickEntryTextField];

What I get looks like this (this is normal when text is not entered into NSTextField): enter image description here

Oh yes, I know I don’t manage my memory ... I’m just trying to get this to work. Thank!

+3
source share

Source: https://habr.com/ru/post/1792654/


All Articles