iOS 11在键入时添加智能引号。在macOS中,我们可以通过以下设置禁用NSTextView上的智能引号:
textView.automaticQuoteSubstitutionEnabled = NO; UITextField和UITextView似乎都没有此属性或enabledTextCheckingTypes属性。如何在iOS 11上禁用智能报价?
发布于 2017-07-06 02:16:38
智能引号和其他功能(如智能破折号)通过UITextField和UITextView采用的UITextInputTraits Protocol进行控制。
具体地说,smartQuotesType属性可以设置为.default、.yes或.no之一。目前还没有关于这些值的更多文档,但是.yes和.no是不言而喻的。我对.default的猜测是,系统将使用textContentType和isSecureTextEntry等属性来确定适当的行为。
例如,默认情况下,文本内容类型的电子邮件、密码或URL可能会禁用智能报价,而职务可能默认为启用。我想默认情况下,安全文本输入字段也会禁用smarts。
为输入视图设置适当的文本内容类型可以显著改善用户体验,强烈建议您这样做。
发布于 2018-02-08 14:27:35
我不认为对于某些语言,smartQuotesType和smartQuotesType是很好的实践。
为我们应用程序中的每个文本输入设置这些属性:
if (@available(iOS 11.0, *)) {
textView.smartDashesType = UITextSmartDashesTypeNo;
textView.smartQuotesType = UITextSmartQuotesTypeNo;
textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo;
} else {
// Fallback on earlier versions
}创建一个类别来禁用这些“智能”功能是没有意义的(bug):
- (UITextSmartDashesType)smartDashesType {
return UITextSmartDashesTypeNo;
}
- (UITextSmartQuotesType)smartQuotesType {
return UITextSmartQuotesTypeNo;
}
- (UITextSmartInsertDeleteType)smartInsertDeleteType {
return UITextSmartInsertDeleteTypeNo;
}因此,我尝试通过方法swizzling永久禁用这些功能:
#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破解私有方法总是很有吸引力的……
发布于 2017-09-24 00:55:45
我有一个问题--我经常通过我的iPad专业版使用Prompt和NX。在设置中关闭“智能标点”起作用了。
https://stackoverflow.com/questions/44932863
复制相似问题