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:
![](https://i0.wp.com/www.albertopasca.it/whiletrue/wp-content/uploads/2021/11/ios-hidden-menu-02.png?resize=311%2C89&ssl=1)
And this is the dictionary definition for pizza on simulator:
![](https://i0.wp.com/www.albertopasca.it/whiletrue/wp-content/uploads/2021/11/ios-hidden-menu-dict.png?resize=396%2C744&ssl=1)
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!