1

我将 NSKernAttributeName 设置为 iOS 6 上 UITextView 的属性文本属性上的不同浮点值,并且在特定范围内。每次使用属性文本的 enumerateAttribute 选项块方法检索值时,Kerning 设置为 0。代码如下。

恢复

        NSAttributedString *currentText = _textView.attributedText;
        [currentText enumerateAttribute:NSKernAttributeName inRange:NSMakeRange(0, currentText.length) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(id value, NSRange range, BOOL *stop){
              float value = [(NSNumber *)value floatValue];
              //Do something with value, but logs show value is always 0 
        }];

贮存

      NSMutableAttributedString *updatedText = self.textView.attributedText.mutableCopy; 
     _kernValue += 0.1f;
     NSDictionary *attributes = @{
                                 NSForegroundColorAttributeName: UIColor.linkColor,
                                 NSFontAttributeName: [UIFont systemFontOfSize:14.0],
                                 NSKernAttributeName: [NSNumber numberWithFloat:_kernValue]
                                 };

     NSMutableAttributedString *replacementString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ", myString] attributes:attributes];
     [updatedText replaceCharactersInRange:myRange withAttributedString:replacementString];
    self.textView.attributedText = updatedText;
4

1 回答 1

0

NSAttributedString标题:

UIKIT_EXTERN NSString *const NSKernAttributeName NS_AVAILABLE_IOS(6_0);                //

NSNumber 包含浮点值,以点为单位;修改默认字距的数量。0 表示禁用字距调整。(注意:iOS 不支持 nil 和 0 以外的值)

于 2013-09-26T08:40:12.887 回答