有没有一种可行的方法让NSPredicateEditor调整NSTextField的大小
我得到的只是NSPredicateEditorRowTemplate的子类,并在我的类中编写以下函数:
- (void)setTextFieldFrameWithPredicateEditor:(NSPredicateEditor *)predicateEditor{
NSArray *arr = [self templateViews];
NSView *view = [arr lastObject];
NSSize needSize = NSMakeSize(NSMaxX(predicateEditor.frame), 17);
[view setFrameSize:needSize];
}通过[view setAutoresizingMask:(NSViewMaxXMargin | NSViewWidthSizable)]设置锚点(页边距)不会产生任何影响
我每次在函数-(IBAction)predicateEditorChanged:(NSPredicateEditor *)sender中按下一个按钮来显示NSPredicateEditor时,都会调用这个函数。它似乎工作正常,但当我多次更改设置时,NSPredicateEditor的大小调整开始工作不正确。
有什么需要帮忙的吗?
发布于 2012-10-19 06:26:53
一种选择是创建自定义NSPredicateEditorRowTemplate并覆盖templateViews方法。
如下所示:
- (NSArray *)templateViews {
NSArray *views = [super templateViews];
NSView *lastView = [views lastObject];
NSRect viewFrame = lastView.frame;
viewFrame.size.width = 100.0f;
lastView.frame = viewFrame;
return views;
}然后将宽度设置为您需要的任何值。
https://stackoverflow.com/questions/10072076
复制相似问题