zoukankan      html  css  js  c++  java
  • iOS微信朋友圈 评论点击姓名功能

    可以使用PPLabel来实现这个功能,下载代码https://github.com/petrpavlik/PPLabel。

    这个demo有两个小bug:

    1、如果最后一个单词后面没有空格字符,那么不能点击。

    修改办法:在ViewController中,有一个代理方法:

    - (void)highlightWordContainingCharacterAtIndex:(CFIndex)charIndex 

    将这个代理方法中的代码:

     if (end.location == NSNotFound) {

            end.location = string.length-1; //last word was selected

        }

    修改成:

     if (end.location == NSNotFound) {

            end.location = string.length//last word was selected

        }

     

    2、这个label中的最后一行无法点击

    修改办法:

    在PPlabel.m中,有以下代码:

    - (CGRect)textRect {

        CGRect textRect = [self textRectForBounds:self.bounds limitedToNumberOfLines:0];

        textRect.origin.y = (self.bounds.size.height - textRect.size.height)/2;

        if (self.textAlignment == NSTextAlignmentCenter) {

            textRect.origin.x = (self.bounds.size.width - textRect.size.width)/2;

        }

        if (self.textAlignment == NSTextAlignmentRight) {

            textRect.origin.x = self.bounds.size.width - textRect.size.width;

        }

        

        return textRect;

    }

    将其修改为:

    - (CGRect)textRect {

        CGRect textRect = [self textRectForBounds:self.bounds limitedToNumberOfLines:0];

        textRect.origin.y = (self.bounds.size.height - textRect.size.height)/2;

        textRect.size.height += 100;

        if (self.textAlignment == NSTextAlignmentCenter) {

            textRect.origin.x = (self.bounds.size.width - textRect.size.width)/2;

        }

        if (self.textAlignment == NSTextAlignmentRight) {

            textRect.origin.x = self.bounds.size.width - textRect.size.width;

        }

        

        return textRect;

    }

    为什么要+100?

    因为用CoreText在计算点击的字符位置时,textRect大小造成最后一行无法统计,将高度增加一部分,可以避免在计算点击的字符位置时造成最后一行遗漏。

  • 相关阅读:
    uboot的Makefile分析
    S3C2440上触摸屏驱动实例开发讲解(转)
    linux嵌入式驱动软件开发(csdnblog)
    [连接]研究MSN的一些参考资料(MSNP15)
    关于Asp.net中使用以下代码导出Excel表格的问题
    FCKEditor在Asp.net的安装
    奥运后,接手两个项目,PECT培训,CIW培训,系分考试...........一堆流水帐
    [转]甩掉数据字典,让Sql Server数据库也来一个自描述
    SQL Server 调优将会用到的非常好的DMV
    SQL Server 监视数据文件大小变化
  • 原文地址:https://www.cnblogs.com/zengyanzhi/p/3862595.html
Copyright © 2011-2022 走看看