I have a tooltip:
cellView.textField.toolTip = cellView.textField.stringValue;
It shows always, but I need to show tooltip only if text clipped... How I can achieve it?
I think you can do this by implementing the text field delegate method, controlTextDidEndEditing, and checking the size of the text. I found that the size returned by sizeWithAttributes: didn't match the size I would have expected when I filled the text field, so I just determined the value I needed for my if statement empirically (in this example I had the text field's value bound to a 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];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.