I've got it working with the following code. One miss though is if some text in the attributedstring has not been set a font-attribute it will not be updated. So i had to encapsulate everything with font-attributes.
- (void)recalculateSizeChangeInAttributedString {
if(self.attributedStringOriginal == nil) {
self.attributedStringOriginal = [self.attributedString copy];
}
CFMutableAttributedStringRef tempString = CFAttributedStringCreateMutableCopy(CFAllocatorGetDefault(), self.attributedStringOriginal.length, (CFMutableAttributedStringRef)self.attributedStringOriginal);
int lastIndex = 0;
int limit = CFAttributedStringGetLength(tempString);
for (int index = 0; index < limit;) {
CFRange inRange = CFRangeMake(0, limit - index);
CFRange longestEffective;
CTFontRef font = (CTFontRef)CFAttributedStringGetAttribute(tempString, index, kCTFontAttributeName, &longestEffective);
if(font != nil) {
// log for testing
NSLog(@"index: %i, range: %i - %i, longest: %i - %i, attribute: %@",
index, inRange.location,
inRange.location + inRange.length,
longestEffective.location, longestEffective.location + longestEffective.length,
@"..."
);
// alter the font and set the altered font/attribute
int rangeEnd = longestEffective.length != 0 ? longestEffective.length : 1;
CTFontRef modifiedFont = CTFontCreateCopyWithAttributes(font, CTFontGetSize((CTFontRef)font) * sizeFactor, NULL, NULL);
CFAttributedStringSetAttribute(tempString, CFRangeMake(index, rangeEnd), kCTFontAttributeName, modifiedFont);
CFRelease(modifiedFont);
}
// make next loop continue where current attribute ended
index += longestEffective.length;
if(index == lastIndex)
index ++;
lastIndex = index;
}
self.attributedString = (NSMutableAttributedString *)tempString;
CFRelease(tempString);
}