iOS 隐藏UITextView 、UITextField 长按弹出菜单栏

iOS 17之后,长按会有一个自动填充的菜单,以及文本选中后的菜单改如何隐藏呢?可以用如下方法来隐藏。

  • 创建一个类,继承UITextView或者UITextField
  • 重新相关方法 canPerformAction:withSender:buildMenuWithBuilder

相关代码如下

swift 复制代码
//
//  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
相关推荐
sg_knight27 分钟前
Claude Code 安装指南(Windows / macOS)
windows·macos·llm·ai编程·claude·code·claude-code
m0_6470579627 分钟前
PyCharm 2023.2.5 Conda Interpreter 解析失败问题排查与解决(macOS)
macos·pycharm·conda
青芒.31 分钟前
macOS Java 多版本环境配置完全指南
java·开发语言·macos
TheNextByte11 小时前
如何使用 7 种解决方案将照片从Mac传输到三星
macos
小鹿软件办公4 小时前
苹果因通信问题撤回面向旧款 iPhone 和 iPad 的系统更新
ios·iphone
Thomas_YXQ14 小时前
Unity3D在ios平台下内存的优化详解
开发语言·macos·ios·性能优化·cocoa
FAFU_kyp17 小时前
RISC0_ZERO项目在macOs上生成链上证明避坑
开发语言·后端·学习·macos·rust
b20772117 小时前
Flutter for OpenHarmony 身体健康状况记录App实战 - 提醒设置实现
python·flutter·macos·cocoa·harmonyos
TheNextByte118 小时前
iPhone 与Android :有什么区别?
android·cocoa·iphone
claem20 小时前
Mac端 Python脚本创建与理解
开发语言·python·macos