OGeek|极客世界-中国程序员成长平台

标题: iphone - TTTAttributedLabel 中的单词被截断 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:11
标题: iphone - TTTAttributedLabel 中的单词被截断

我正在使用 TTTAttributedLabel 但现在当我尝试显示一些链接时,它会从中心剪切单词,就像您在附图中看到的那样,单词“fun”在单词“f”和“un”出现后被截断下一行。但我希望完整的单词应该显示在第一行或下一行。任何帮助。

enter image description here

enter image description here

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



            }



Best Answer-推荐答案


在最新版本的 TTTAttributedLabel 中,默认的 linkAttributes 属性已更新为默认自动换行。确保标签和 linkAttributes 都具有所需的换行模式(标签的 lineBreakMode 属性;NSMutableParagraphStyle lineBreakModelinkAttributes )。

关于iphone - TTTAttributedLabel 中的单词被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15896445/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4