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

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

  •  
  •   yiplee ·
    yiplee · 2014-07-30 14:35:27 +08:00 · 5341 次点击
    这是一个创建于 3529 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如 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   ·   我们的愿景   ·   实用小工具   ·   971 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.