NSAttributedString写作方向 [英] NSAttributedString Writing Direction

查看:325
本文介绍了NSAttributedString写作方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改NSAttributedString中的写入方向。但是,我真的很难搞清楚如何去做。

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 = CTFontCreateWithName((CFStringRef)@"ArialRoundedMTBold", 16, NULL);

NSDictionary *attrDictionary = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)fontRef,(NSString *)kCTFontAttributeName, nil];
CFRelease(fontRef);

NSAttributedString *attString=[[NSAttributedString alloc] initWithString:self.stringMap attributes:attrDictionary];

self.attString = attString;

这是我初始化我的NSAttributedString的代码,我读过有关常量 kCTWritingDirectionRightToLeft ,我觉得我必须把它放在某个地方,但我可以弄清楚在哪里和如何。

This is the code in which I initialise my NSAttributedString and I have read about the constant kCTWritingDirectionRightToLeft and I feel like I have to put it in somewhere but I can figure out where and how.

有人有任何建议吗?

推荐答案

我仔细阅读了文档。

I read more carefully the doc.

我将使用 NSFontAttributeName NSWritingDirectionAttributeName 因为我比使用所有网桥 stuff,还有简写语法。

I'll use NSFontAttributeName and NSWritingDirectionAttributeName since I'm more confortable with them than using all the bridge stuff, and also shorthand syntax.

所以 NSWritingDirectionAttributeName 等待 NSArray 的NSNumbers。那就是问题所在。
其中一个数字必须是 NSWritingDirection LeftToRight RightToLeft ),另一个是 NSTextWritingDirection 嵌入覆盖)。

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)]};

来源: NSWritingDirectionAttributeName的文档

这篇关于NSAttributedString写作方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆