28 lines
1.1 KiB
Objective-C
28 lines
1.1 KiB
Objective-C
//
|
||
// MSRTL.m
|
||
// YuMi
|
||
//
|
||
// Created by duoban on 2024/4/11.
|
||
//
|
||
|
||
#import "NSMutableAttributedString+MSRTL.h"
|
||
|
||
|
||
@implementation NSMutableAttributedString (MSRTL)
|
||
|
||
/// 用来改变布局方向,插入此空白字符串,则转化为RTL布局
|
||
+ (NSMutableAttributedString *)createBlankAttributeToMSRTL {
|
||
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:@"\u202B"];
|
||
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:0], NSForegroundColorAttributeName: UIColor.clearColor} range:NSMakeRange(0, attribute.length)];
|
||
return attribute;
|
||
}
|
||
|
||
/// 用来解决YYText在RTL下的bug,如果昵称是阿语,整个富文本宽度计算会有误,在昵称前插入此空白字符串,可以修正布局。“i”可以是随意字母或中文
|
||
+ (NSMutableAttributedString *)createBlankAttributeToMSLTR {
|
||
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:@"i"];
|
||
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:0], NSForegroundColorAttributeName: UIColor.clearColor} range:NSMakeRange(0, attribute.length)];
|
||
return attribute;
|
||
}
|
||
|
||
@end
|