V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
hustlzp
V2EX  ›  iDev

如何实现类似微信朋友圈评论的这种排版效果?

  •  
  •   hustlzp ·
    hustlzp · 2015-08-29 16:15:17 +08:00 · 6612 次点击
    这是一个创建于 3155 天前的主题,其中的信息可能已经有所发展或是发生改变。


    类似微信朋友圈评论的这种效果:可点击的人名和普通的文字混排。

    NSAttributedString 倒是可以实现文本混排,但是貌似不太好支持点击。

    各位知道如何实现吗?
    12 条回复    2015-08-31 20:35:25 +08:00
    hoogle
        1
    hoogle  
       2015-08-29 16:32:47 +08:00
    irobbin
        2
    irobbin  
       2015-08-29 16:33:31 +08:00
    你不知道有个东西叫做 TTTAttributedLabel 吗?
    hustlzp
        3
    hustlzp  
    OP
       2015-08-29 16:35:16 +08:00
    额,好像找到解决方法了,刚才看了下 @hoogle 的项目:

    https://github.com/singro/v2ex

    在单个话题页使用 TTTAttributedLabel 实现了类似的混排。

    具体在这里:

    https://github.com/hustlzp/v2ex/blob/master/v2ex-iOS/Views/V2TopicReplyCell.m#L406
    hustlzp
        4
    hustlzp  
    OP
       2015-08-29 16:35:37 +08:00
    @irobbin 刚刚才知道...
    hustlzp
        5
    hustlzp  
    OP
       2015-08-29 16:37:41 +08:00
    @hoogle

    我刚转行 iOS 开发...你的开源项目很棒, THX !
    HappyHacking
        6
    HappyHacking  
       2015-08-29 16:46:27 +08:00   ❤️ 1
    我用越狱的 iPhone 加上 Reveal ,看各种第三方的 App 的 UI ,微信的也看过,它的这个文字显示的类名叫做 RichText ,不过我在 GitHub 上没有找到相应的代码,最后用 DTCoreText 实现了
    hustlzp
        7
    hustlzp  
    OP
       2015-08-29 16:49:40 +08:00
    @HappyHacking THX , DTCoreText 的 star 数也不少啊~
    hoogle
        8
    hoogle  
       2015-08-29 16:50:30 +08:00   ❤️ 1
    @hustlzp 用 TTTAttributedLabel 可以,也比较方便, 不过它不支持 NSAttachment ,遇到自定义表情什么的就没办法了。
    fhefh
        9
    fhefh  
       2015-08-29 20:18:50 +08:00
    mark 学习了~
    hustlzp
        10
    hustlzp  
    OP
       2015-08-31 17:23:23 +08:00
    @hoogle 如果需要支持自定义表情,有什么库可以推荐下吗?或者大概的思路?谢谢了!
    hoogle
        11
    hoogle  
       2015-08-31 19:05:56 +08:00
    NSAttributedString 里有 link 类型, 加上 1 楼的增加点击的响应
    hustlzp
        12
    hustlzp  
    OP
       2015-08-31 20:35:25 +08:00
    @hoogle THX
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4406 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:10 · PVG 18:10 · LAX 03:10 · JFK 06:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.