[英]Multiple text alignment with same label using NSMutableAttributedString on iOS
我想使用NSMutableAttributedString
為我的標簽設置文本方向。 例如,我有聊天視圖,其中包含消息和時間。 我想使用UILabel
設置消息的左對齊和時間的右對齊。
我使用了以下代碼,但它不起作用,
NSString *Time = [Functions stringFromGivenDate:msg.time withFormate:@"hh:mm a"];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",msg.text,Time]];
NSDictionary *attrDictionary = @{NSWritingDirectionAttributeName:@[@(NSTextWritingDirectionOverride)]};
[str addAttributes:attrDictionary range:NSMakeRange(msg.text.length+1, Time.length)];
如果我理解正確,這應該會有所幫助:
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.alignment = alignment;// type NSTextAlignment
NSDictionary *attributtes = @{NSParagraphStyleAttributeName : style,};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.