【问题标题】:Adding a Dotted red line under characters in a UITextView在 UITextView 中的字符下添加虚线红线
【发布时间】:2012-11-04 15:14:26
【问题描述】:

我正在尝试为 UITextView 创建自定义拼写检查器。

为了显示一个单词拼写错误,我需要在拼写错误的单词下方添加“红色虚线”。 为此,这是我认为可行的方法 -

我创建了一个字典,其中包含键 NSUnderlineStyleAttributeName 的值。 然而,它的作用是,它确实在字符下划线,但它没有点图案。 另外,设置 strokeColorAttribute 似乎也没有任何效果。

这是我的代码 -

    NSMutableDictionary *misspelledAttributes = [NSMutableDictionary dictionary];
    [misspelledAttributes setObject:[NSNumber numberWithInt:kCTUnderlineStyleThick|kCTUnderlinePatternDot] forKey:NSUnderlineStyleAttributeName];
    [misspelledAttributes setObject:[UIColor redColor] forKey:NSStrokeColorAttributeName];

将属性设置为特定范围的属性字符串 -

NSMutableAttributedString *attrString = [self.textView.attributedText mutableCopy];
[attrString addAttributes:misspelledAttributes range:wordRange]; 

如果有人能帮我解决这个问题并指出我错过了什么/做错了什么,那就太好了。

【问题讨论】:

    标签: ios6 uitextview spell-checking


    【解决方案1】:

    我认为您将不得不找到 NSAttributedString 以外的方法。

    据我所知,NSUnderlineStyleAttributeName 在 iOS 中的唯一值选择是 NSUnderlineStyleNone 或 NSUnderlineStyleSingle,它们代表数字。

    NSUnderlineColorAttributeName 似乎仅适用于 Mac OS。

    【讨论】:

    • 我想这可能是新的,但在我之前的测试和我链接到的文档中,它说:可用性:在 OS X v10.0 及更高版本中可用。
    猜你喜欢
    • 2012-06-04
    • 2013-02-21
    • 2017-09-06
    • 1970-01-01
    • 2023-01-24
    • 2018-08-27
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多