iphone - 断字库不适用于 iOS 5

标签 iphone ios sdk hyphenation

我刚刚尝试了 Tupil 的连字符库。

这里提到了http://blog.tupil.com/adding-hyphenation-to-nsstring/ .

但是虽然它在 iOS 4.3 下工作得很好,但我没有让它在 iOS 5 上工作。

还有其他我可以使用的框架吗?我听说过 CoreText,但我不知道从哪里开始。

提前致谢 马丁

最佳答案

我意识到已经有几年了,但我刚刚发现有一个 Core Foundation 函数建议连字点:CFStringGetHyphenationLocationBeforeIndex .它只适用于少数几种语言,但看起来它可能对窄标签问题很有帮助。

更新:

这是一些示例代码。这是一个 CLI 程序,显示在何处连接单词:

#include <Cocoa/Cocoa.h>


int main(int ac, char *av[])
{
    @autoreleasepool {

    if(ac < 2) {
        fprintf(stderr, "usage:  hyph  word\n");
        exit(1);
    }
    NSString *word = [NSString stringWithUTF8String: av[1]];
    unsigned char hyspots[word.length];
    memset(hyspots, 0, word.length);
    CFRange range = CFRangeMake(0, word.length);
    CFLocaleRef locale = CFLocaleCreate(NULL, CFSTR("en_US"));
    for(int i = 0; i < word.length; i++) {
        int x = CFStringGetHyphenationLocationBeforeIndex(
                    (CFStringRef) word, i, range,
                    0, locale, NULL);
        if(x >= 0 && x < word.length)
            hyspots[x] = 1;
    }
    for(int i = 0; i < word.length; i++) {
        if(hyspots[i]) putchar('-');
        printf("%s", [[word substringWithRange: NSMakeRange(i, 1)] UTF8String]);
    }
    putchar('\n');

    }

    exit(0);
}

这是构建和运行它时的样子:

$ cc -o hyph hyph.m -framework Cocoa
$ hyph accessibility
ac-ces-si-bil-i-ty
$ hyph hypothesis
hy-poth-e-sis

这些连字符与 OS X 词典完全一致。我将它用于 iOS 中的窄标签问题,它对我来说效果很好。

关于iphone - 断字库不适用于 iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203767/

相关文章:

iphone - 展开继续问题

ios - Calendar.nextDate() 在使用 .backward 作为方向时表现得非常奇怪。仅限每月最后一天

android - 在 SDK 管理器中找不到 android sdk 2.3.4

iPhone SDK : Is it allowed having two ad banners in a uiview?

iOS 应用 ID - 应用内购买已禁用(无法启用)

ios - DerivedData/ModuleCache 中的 fatal error

长按时出现 iOS 7 UITableViewCell 按钮

cocoa - 如何在 xCode 4 中添加 10.5 的基础 SDK

objective-c - 实现 Facebook iOS SDK - 无 "fbDidLogin"回调

iphone - UIImage 不是编译时常量,Xcode 4