作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚尝试了 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/
我是一名优秀的程序员,十分优秀!