How to include ttf fonts in iPhone app
Categories: iPhone on Jul.30, 2009
Хороший способ подключения шрифтов.
Кидаем в ресурсы наш шрифт. Вставляем и выполняем функцию.
- NSUInteger loadFonts()
- {
- NSUInteger newFontCount = 0;
- NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
- const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
- if (frameworkPath) {
- void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
- if (graphicsServices) {
- BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
- if (GSFontAddFromFile)
- for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"TTF" inDirectory:nil])
- newFontCount += GSFontAddFromFile([fontFile UTF8String]);
- }
- }
- return newFontCount;
- }
Смотрим что у нас появилось
- NSLog(@"%@",[UIFont familyNames]);
Similar posts:


(3 votes, average: 3.67 out of 5)


August 7th, 2009 on 10:07 am
Наверное стоит упомянуть, что для работы dlopen нужно подключить dlfcn.h
August 7th, 2009 on 1:08 pm
сорри….
Вы правы :)
September 29th, 2009 on 4:50 pm
>void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
как к такому ходу отнеслись цензоры AppStore?
September 29th, 2009 on 7:44 pm
В основном на ваш страх и риск. В следующей версии может и не работать это!
December 22nd, 2009 on 7:30 pm
Еще такой нюанс.
В файле .mm не закомпилилось – победил так:
это
BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, “GSFontAddFromFile”);
заменил на
BOOL (*GSFontAddFromFile)(const char*);
(void*)GSFontAddFromFile = dlsym(graphicsServices, “GSFontAddFromFile”);