Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicateEditor does not resize NSTextField

Is there a workable way to make NSPredicateEditor resize NSTextField?

All I got is to subclass NSPredicateEditorRowTemplate and write in my class the following function:

- (void)setTextFieldFrameWithPredicateEditor:(NSPredicateEditor *)predicateEditor{
    NSArray *arr = [self templateViews];
    NSView *view = [arr lastObject];
    NSSize needSize = NSMakeSize(NSMaxX(predicateEditor.frame), 17);
    [view setFrameSize:needSize];
}

There is no effect from setting anchors(margins) by [view setAutoresizingMask:(NSViewMaxXMargin | NSViewWidthSizable)]

I call this function every time the show NSPredicateEditor by pressing a button, and every time in function -(IBAction)predicateEditorChanged:(NSPredicateEditor *)sender. It seems working correctly, but when many times I change the settings NSPredicateEditor at some time resizing starts to work not correct.

Any help please.

like image 778
Kira Avatar asked Mar 20 '26 17:03

Kira


1 Answers

One option would be to create a custom NSPredicateEditorRowTemplate and override the templateViews method.

Like this:

- (NSArray *)templateViews {
    NSArray *views = [super templateViews];
    NSView *lastView = [views lastObject];
    NSRect viewFrame = lastView.frame;
    viewFrame.size.width = 100.0f;
    lastView.frame = viewFrame;
    return views;
}

And then set the width to whatever you need it to be.

like image 114
Tap Forms Avatar answered Mar 22 '26 20:03

Tap Forms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!