美文网首页
Weex 组件在iOS中文本显示不全问题

Weex 组件在iOS中文本显示不全问题

作者: OOOlive | 来源:发表于2019-09-27 11:07 被阅读0次

    在iOS 10以上系统手机,使用<text>组件时,若文本中有多个换行,会导致文本展示不全,最后一行被截掉一半的问题。 如下图所示:


    问题示例

    这个问题在Android中好像并没有,所以在WeexSDK的WXTextComponent.mm中找到- (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth方法:

    - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
    {
        ...
        
        if (WX_SYS_VERSION_LESS_THAN(@"10.0")) {
            // there is something wrong with coreText drawing text height, trying to fix this with more efficent way.
            if(actualLineCount && actualLineCount < lineCount) {
                suggestSize.height = suggestSize.height * actualLineCount / lineCount;
            }
            return CGSizeMake(aWidth, suggestSize.height);
        }
        return CGSizeMake(aWidth, totalHeight);
    }
    
    

    问题就出在这段高度计算上,将上面这段代码修改一下即可:

    
    - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
    {
        ...
        
        // gl fix 解决iOS10以上手机,文本换行导致的文本展示不全,高度计算问题
        if(actualLineCount && actualLineCount <= lineCount) {
            suggestSize.height = suggestSize.height * actualLineCount / lineCount;
            return CGSizeMake(aWidth, suggestSize.height);
        } else {
            return CGSizeMake(aWidth, totalHeight);
        }
    }
    

    重新测试了下,修复了,暂时没发现有别的问题。

    相关文章

      网友评论

          本文标题:Weex 组件在iOS中文本显示不全问题

          本文链接:https://www.haomeiwen.com/subject/bxiouctx.html