I think you can do this by implementing the text field delegation method, controlTextDidEndEditing and checking the text size. I found that the size returned by sizeWithAttributes: does not match the size that I would have expected when filling out the text field, so I just determined the value that I need for the if if expression empirically (in this example, I had the value of the text field value for the property, theText).
-(void)controlTextDidEndEditing:(NSNotification *)obj {
NSLog(@"%@",NSStringFromRect([obj.object frame]));
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:13] forKey:@"NSFontAttributeName"];
NSSize size = [theText sizeWithAttributes:dict];
NSLog(@"%@",NSStringFromSize(size));
if (size.width >69) {
[obj.object setToolTip:theText];
}
}
source
share