NSAttributedString Writing Direction

怎甘沉沦 提交于 2019-12-01 17:55:13

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!