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;