I am parsing simple HTML into an attributed string (for iOS 6), and I can't seem to get nested attributes to work. eg:
This <font color="red">is <i>what</i> I mean</font> to achieve.
I am correctly applying the attributes, but the italicization never takes affect, unless it is done on a range that the font color doesn't affect. My googling has not brought up any related issues, and I'm wondering if NSAttributedString even supports this at all, or if attributes ranges must be non overlapping.
EDIT:
I've reworded the question to be clearer. The answer to the question is a resounding NO, you must specify all attributes for a given range in a single attribute dictionary, they do not combine. I've accepted a reasonable answer to the original question as correct.
You can achieve the result you want with NSMutableAttributedString
. You simply need to set each attribute separately. E.g.
NSString *string = @"This is a test";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string attributes:nil];
NSMutableDictionary *attributes = [@{NSForegroundColorAttributeName: [UIColor redColor]} mutableCopy];
[string setAttributes:attributes range:[string rangeOfString:@"is a test"];
[attributes setObject:font forKey:NSFontAttributeName];
[string setAttributes:attributes range:[string rangeOfString:@"test"];