阅读量:0
iOS 17之后,长按会有一个自动填充的菜单,以及文本选中后的菜单改如何隐藏呢?可以用如下方法来隐藏。
- 创建一个类,继承UITextView或者UITextField
- 重新相关方法
canPerformAction:withSender:
与buildMenuWithBuilder
相关代码如下
// // CNTextView.m // test3 // // Created by xxx on 2024/8/2. // #import "CNTextView.h" @implementation CNTextView /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ -(void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder{ if (@available(iOS 17.0, *)) { //隐藏自动填充 [builder removeMenuForIdentifier:UIMenuAutoFill]; } [super buildMenuWithBuilder:builder]; } //隐藏其他菜单按钮 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { return NO; } @end