[iOS: objective - c] framework & library 에서 custom font 사용하기
1. 커스텀 폰트를 프로젝트에 추가한다
2. info.plist 추가
3.
-(void) addCustomFont {
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
NSString *fontPath = [frameworkBundle pathForResource:@"NanumMyeongjo" ofType:@"ttf"];
NSData *inData = [NSData dataWithContentsOfFile:fontPath];
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"%s Failed to load font: %@", __FUNCTION__, errorDescription);
CFRelease(errorDescription);
}
fontPath = [frameworkBundle pathForResource:@"NanumMyeongjoBold" ofType:@"ttf"];
inData = [NSData dataWithContentsOfFile:fontPath];
provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"%s Failed to load font: %@", __FUNCTION__, errorDescription);
CFRelease(errorDescription);
}
fontPath = [frameworkBundle pathForResource:@"NanumMyeongjoExtraBold" ofType:@"ttf"];
inData = [NSData dataWithContentsOfFile:fontPath];
provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"%s Failed to load font: %@", __FUNCTION__, errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++) {
NSString *fontFamily = [fontFamilies objectAtIndex:i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog (@"%s font== : %@: %@", __FUNCTION__, fontFamily, fontNames);
}
//
// NSArray *Array = [_labelTitleSize, _labelContentRegistSize, _labelContentAuthSize];
// for (UILabel *label in Array) {
// label.font = [UIFont fontWithName:@"NanumMyeongjo" size:15];
// }
// 모든 라벨에 적용되는데, 사이즈가 같음...
[[UILabel appearance] setFont:[UIFont fontWithName:@"NanumMyeongjo" size:17.0]];
}
4. 적용방법
[patternDesign setTextFont:[UIFont fontWithName:@"NanumMyeongjo" size:1]];
'iOS > Swift + Objective-c' 카테고리의 다른 글
[iOS] Push Notification (APNS) example (0) | 2020.03.06 |
---|---|
[iOS] 프레임워크 시뮬레이터 아키텍처 삭제 (platform doesn't have any non-simulator SDKs) (0) | 2020.03.06 |
[iOS: objective - c] framework & library 에서 custom font 사용하기 (0) | 2018.03.12 |
[iOS] status bar height 구하기 (상태바 높이 구하기) (0) | 2018.01.17 |
[iOS] static library에서 image 사용하기 (0) | 2017.09.05 |