1

I'm setting an NSKernAttributeName to varying float values on the attributedText property of a UITextView on iOS 6, and within specific ranges. Every time the value is retrieved using the enumerateAttribute options block method of the attributedText, the Kerning is set to 0. Code is below.

Retrieval

        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 
        }];

Storage

      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;
roozbubu
  • 1,106
  • 4
  • 14
  • 30

1 Answers1

0

From the NSAttributedString header:

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

NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled. (note: values other than nil and 0 are unsupported on iOS)

art-divin
  • 1,635
  • 1
  • 20
  • 28