By chance i founded this tricks that permit to show a “Dictionary definition” for the selected word in a UITextField on a hidden menu.
Menu contains these actions:
- cut
- copy
- select
- select all
- paste
- suggest
- definition
- indent left
- indent right
It’s a cool tricks, that show an hidden menu with a lot of options, that i never see before!
Watch this:

And this is the dictionary definition for pizza on simulator:

How?
Subclass UITextField and override:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
return [super canPerformAction:action withSender:sender];
}
Instead, if you want to block one or more actions from menu, add sel_isEqual
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if ( sel_isEqual(action, @selector(paste:)) ) return NO;
if ( sel_isEqual(action, @selector(copy:)) ) return NO;
// [...] etc etc
return [super canPerformAction:action withSender:sender];
}
that’s all!
Latest posts by Alberto Pasca (see all)
- Swift – Simple full screen loader - 11 August 2022
- macOS – Disable microphone while typing - 11 April 2022
- iOS – Secure app sensitive information - 25 March 2022