iOS 设备上的一些 Github 客户端是怎么实现代码高亮甚至切换颜色主题的? - V2EX
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
yiplee
1.78D
V2EX    iDev

iOS 设备上的一些 Github 客户端是怎么实现代码高亮甚至切换颜色主题的?

  •  
  •   yiplee
    yiplee 2014-07-30 14:35:27 +08:00 5988 次点击
    这是一个创建于 4093 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如 NapCat , iOctocat 等等
    11 条回复    2014-08-25 17:12:20 +08:00
    rekey
        1
    rekey  
       2014-07-30 16:51:35 +08:00
    不会是 webview 吧。。。
    txx
        2
    txx  
       2014-07-30 16:58:24 +08:00
    iOctocat 1.0 是源的 自己去看啊...
    yiplee
        3
    yiplee  
    OP
       2014-07-30 17:37:32 +08:00
    @txx iOctocat 的开源代码在 github 上已经没有了。

    iOctocat 的看上去应该是 webview 。
    xhacker
        4
    xhacker  
       2014-07-30 17:57:09 +08:00   1
    @yiplee: 还在的。

    https://github.com/dennisreimann/ioctocat

    I removed the contents of this repo, because people kept confusing this for the current version that is available n the App Store. Please note that the source is still available and can be used, just go back to the last ref before the cleaning - just keep in mind that this version is not updated for iOS 7.
    Smartype
        6
    Smartype  
       2014-07-30 19:35:38 +08:00
    Textastic 是自己写了一个的UITextView, 我分析过,基本上就是重新造了一个UITextView,而且支持编辑/高亮/选择等。绘制的 OnDemand 的,然后绘制操作(每一行)塞到一个NSOperationQueue里面,在后台绘制layer,然后[view setContent:layer]。其他的应该都是UIWebView。这些应用在iOS开发WebView内容可编辑之前(iOS 5.0)应该都是没有的。
    yiplee
        7
    yiplee  
    OP
       2014-07-30 20:44:39 +08:00
    @Smartype 自定义的 UITextView 要支持代码高亮并且几十种不同的语言都要支持,工作量貌似很大。

    只显示代码的话最简便的就是 webview 了。 NapCat 的效果不错,不确定是不是 webview 。
    txx
        8
    txx  
       2014-07-30 21:15:54 +08:00
    @yiplee class-dump + reveal 分析下~
    gangsta
        9
    gangsta  
       2014-07-31 13:12:16 +08:00   1
    代码高亮的话可以试试: webview + google-code-prettify
    krafttuc
        10
    krafttuc  
       2014-08-02 11:00:18 +08:00   1
    做语法高亮一般来说要么套用正则,要么做类似编译器的语法分析。很多编辑器都采用正则,如 TextMate 的语法 bundle 里就是各种各样的正则。做语法分析的比较少见,毕竟这个工作量更大。我知道的一种方式是构建 Abstract syntax tree http://en.wikipedia.org/wiki/Abstract_syntax_tree

    那么回到iOS上的几种常见的解决方法:

    * WebView。JS渲染,如highlight.js。对只读的文本内容,这种实践最为省力。毕竟提供语法高亮的JS插件很多。
    * UITextView。iOS 7以及之后的版本用 TextKit。如果要支持iOS 7 之前的,可以走到 CoreText 这一层。同样,套正则或者做语法分析。这种实现对做写操作有要求的同学也许可以试试,比 WebView + content editable 这种组合少很多坑。
    kingliangyingjun
        11
    kingliangyingjun  
       2014-08-25 17:12:20 +08:00
    coreText
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2901 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 14:17 PVG 22:17 LAX 07:17 JFK 10:17
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86