I am trying to change the write direction in an NSAttributedString. However, I have a really hard time figuring out how to do it.
CTFontRef fontRef = CTFontC
I read more carefully the doc.
I'll use NSFontAttributeName
and NSWritingDirectionAttributeName
since I'm more confortable with them than using all the bridge
stuff, and also shorthand syntax.
So NSWritingDirectionAttributeName
waits for a NSArray
of NSNumbers. That was the issue.
One of theses numbers must be a NSWritingDirection (LeftToRight or RightToLeft), and the other a NSTextWritingDirection (Embedding or Override).
So, the combinations possibles are (and I think you're looking for the forth one):
NSDictionary *attrDictionary = @{NSFontAttributeName:font,
NSWritingDirectionAttributeName:@[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride)]};
NSDictionary *attrDictionary = @{NSFontAttributeName:font,
NSWritingDirectionAttributeName:@[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionEmbedding)]};
NSDictionary *attrDictionary = @{NSFontAttributeName:font,
NSWritingDirectionAttributeName:@[@(NSWritingDirectionLeftToRight | NSTextWritingDirectionOverride)]};
NSDictionary *attrDictionary = @{NSFontAttributeName:font,
NSWritingDirectionAttributeName:@[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride)]};
Source: Documentation of NSWritingDirectionAttributeName