如何在swift中使用NSWritingDirectionAttributeName?
我在Obj-c中有这段代码:
attrString = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont fontAwesomeFontOfSize:24], NSForegroundColorAttributeName:kHJColorIcon, NSWritingDirectionAttributeName:@[@(NSWritingDirectionRightToLeft | NSTextWritingDirectionOverride)]}];
效果很好!
现在我需要在另一个地方使用相同的代码,但语言很快。
答案 0 :(得分:3)
键NSWritingDirectionAttributeName
需要数值,因此请使用原始值
[NSWritingDirectionAttributeName : [NSWritingDirection.LeftToRight.rawValue | NSTextWritingDirection.Override.rawValue]]
答案 1 :(得分:2)
键NSWritingDirectionAttributeName
需要数字值,因此在您的函数中使用rawValue
,请尝试此操作
let attrString = NSMutableAttributedString(string: "Karthik Test",
attributes: [NSFontAttributeName: UIFont.systemFontOfSize(24),
NSWritingDirectionAttributeName:[NSWritingDirection.RightToLeft.rawValue |
NSTextWritingDirection.Override.rawValue]])