首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 11 -禁用智能引号

iOS 11 -禁用智能引号
EN

Stack Overflow用户
提问于 2017-07-06 01:47:08
回答 3查看 8.9K关注 0票数 17

iOS 11在键入时添加智能引号。在macOS中,我们可以通过以下设置禁用NSTextView上的智能引号:

代码语言:javascript
复制
textView.automaticQuoteSubstitutionEnabled = NO;  

UITextFieldUITextView似乎都没有此属性或enabledTextCheckingTypes属性。如何在iOS 11上禁用智能报价?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-07-06 02:16:38

智能引号和其他功能(如智能破折号)通过UITextFieldUITextView采用的UITextInputTraits Protocol进行控制。

具体地说,smartQuotesType属性可以设置为.default.yes.no之一。目前还没有关于这些值的更多文档,但是.yes.no是不言而喻的。我对.default的猜测是,系统将使用textContentTypeisSecureTextEntry等属性来确定适当的行为。

例如,默认情况下,文本内容类型的电子邮件、密码或URL可能会禁用智能报价,而职务可能默认为启用。我想默认情况下,安全文本输入字段也会禁用smarts。

为输入视图设置适当的文本内容类型可以显著改善用户体验,强烈建议您这样做。

票数 30
EN

Stack Overflow用户

发布于 2018-02-08 14:27:35

我不认为对于某些语言,smartQuotesTypesmartQuotesType是很好的实践。

为我们应用程序中的每个文本输入设置这些属性:

代码语言:javascript
复制
if (@available(iOS 11.0, *)) {
    textView.smartDashesType = UITextSmartDashesTypeNo;
    textView.smartQuotesType = UITextSmartQuotesTypeNo;
    textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo;
} else {
    // Fallback on earlier versions
}

创建一个类别来禁用这些“智能”功能是没有意义的(bug):

代码语言:javascript
复制
- (UITextSmartDashesType)smartDashesType {
    return UITextSmartDashesTypeNo;
}
- (UITextSmartQuotesType)smartQuotesType {
    return UITextSmartQuotesTypeNo;
}
- (UITextSmartInsertDeleteType)smartInsertDeleteType {
    return UITextSmartInsertDeleteTypeNo;
}

因此,我尝试通过方法swizzling永久禁用这些功能:

代码语言:javascript
复制
#import <objc/runtime.h>

@implementation DisableFuckingSmartPunctuation

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [objc_getClass("UITextInputController") class];
        Class myClass = [self class];

        SEL originalSelector = @selector(checkSmartPunctuationForWordInRange:);
        SEL swizzledSelector = @selector(checkSmartPunctuationForWordInRange:);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(myClass, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

- (void)checkSmartPunctuationForWordInRange:(id)arg1 {

}

@end

破解私有方法总是很有吸引力的……

票数 8
EN

Stack Overflow用户

发布于 2017-09-24 00:55:45

我有一个问题--我经常通过我的iPad专业版使用Prompt和NX。在设置中关闭“智能标点”起作用了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44932863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档