简体   繁体   English

在TTTAttributedLabel中切断单词

[英]Word cut off in TTTAttributedLabel

I am using TTTAttributedLabel but now when i try to show some link then it cut the word from the center like you can see in attached image the word "fun" is cut off after word "f" and "un" appears on next line. 我正在使用TTTAttributedLabel,但是现在当我尝试显示一些链接时,它从中心切开了该词,就像您在所附的图像中看到的,在词“ f”之后截断了“ fun”这个词,并且在下一行出现了“ un”。 but i want that the full word should show on first line or in next line. 但我希望完整的单词应显示在第一行或下一行。 Any help. 任何帮助。

在此处输入图片说明

在此处输入图片说明

if ([_label isKindOfClass:[TTTAttributedLabel class]])
            {
                TTTAttributedLabel *tttLabel=(TTTAttributedLabel *)_label;

                                        [tttLabel setDelegate:self];

                    [tttLabel setDataDetectorTypes:UIDataDetectorTypeLink|UIDataDetectorTypePhoneNumber];
                    [tttLabel setLineBreakMode:NSLineBreakByWordWrapping];



                [tttLabel setText:attributedText];
                if ([dic objectForKey:@"texttolink"]!=nil)
                {
                    [tttLabel addLinkToURL:[NSURL URLWithString:[dic objectForKey:@"hyperlink"]] withRange:[text rangeOfString:[dic objectForKey:@"texttolink"] options:NSCaseInsensitiveSearch]];
                }



            }

In the latest version of TTTAttributedLabel, the default linkAttributes property was updated to have word wrap by default. 在最新版本的TTTAttributedLabel中,默认的linkAttributes属性已更新为具有自动换行功能。 Make sure that both the label and the linkAttributes have the desired line break mode ( lineBreakMode property for the label; NSMutableParagraphStyle lineBreakMode for linkAttributes ). 确保标签和linkAttributes都具有所需的换行模式(标签的lineBreakMode属性; linkAttributes NSMutableParagraphStyle lineBreakMode )。

尝试将lineBreakMode设置为NSLineBreakByWordWrapping

label.lineBreakMode = NSLineBreakByWordWrapping;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM