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
Draven
V2EX  ›  iDev

快速构造 NSAttributedString

  •  2
     
  •   Draven ·
    draveness · 2016 年 4 月 17 日 · 3752 次点击
    这是一个创建于 3564 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因为在使用 NSAttributedString 的过程中感觉非常的不方便,所以一年前写了这么一个框架 Typeset 来快速生成 NSAttributedString

    使用如下的语法

    @"Hello'.red.fontSize(20);
    

    同样也支持对 UILabel 设置样式, 可以在 typesetBlock 中对字符串预先进行匹配,

    如下:如果出现了 @"type" 就会把 @"type" 变成紫色,出现了 @"set" 就会变为蓝色

    label.typesetBlock = TSBlock(fontSize(40)
                           .match(@"type").purple
                           .match(@"set").blue);
    label.text = @"Hello typeset, hello.";
    

    觉得有用的朋友可以点个 star https://github.com/Draveness/Typeset

    13 条回复    2016-04-25 22:25:54 +08:00
    mthli
        1
    mthli  
       2016 年 4 月 17 日 via Android
    支持!
    canaan
        2
    canaan  
       2016 年 4 月 17 日
    遭不住了,这么优秀。
    silencewwt
        3
    silencewwt  
       2016 年 4 月 17 日
    惊了个呆 看见头像我就滚进来了
    ahmiao
        4
    ahmiao  
       2016 年 4 月 17 日
    正好今天还看到这个: https://github.com/delba/TextAttributes
    xi_lin
        5
    xi_lin  
       2016 年 4 月 17 日
    赞,好想法!
    Draven
        6
    Draven  
    OP
       2016 年 4 月 17 日
    @ahmiao 我是看到这个也火了。。我就把一年前写的贴出来了
    Draven
        7
    Draven  
    OP
       2016 年 4 月 17 日
    @mthli 蛤蛤
    yautou
        8
    yautou  
       2016 年 4 月 17 日
    模拟器实时生效预览效果是什么插件吗?
    airdrop
        9
    airdrop  
       2016 年 4 月 17 日
    同问模拟器实时运行是怎么实现的
    yoa1q7y
        10
    yoa1q7y  
       2016 年 4 月 17 日   ❤️ 1
    nathanw
        11
    nathanw  
       2016 年 4 月 17 日
    https://github.com/delba/TextAttributes 和这相比有什么不同之处么?
    Draven
        12
    Draven  
    OP
       2016 年 4 月 17 日
    @nathanw TextAttributes 只能在 Swift 上实现 链式语法,在 OC 上一样得用方括号调用
    PopeyeLau
        13
    PopeyeLau  
       2016 年 4 月 25 日
    木有 swift 版么.
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5795 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 02:24 · PVG 10:24 · LAX 18:24 · JFK 21:24
    ♥ Do have faith in what you're doing.