NSAttributedString Writing Direction

前端 未结 1 481
失恋的感觉
失恋的感觉 2021-01-12 17:51

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         


        
相关标签:
1条回答
  • 2021-01-12 18:21

    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

    0 讨论(0)
提交回复
热议问题