Non-bundle external fonts for iOS Application
up vote
0
down vote
favorite
How to use non-bundle custom fonts in my iOS Application? I want to add font to app via iCloud or from internet and use it inside.
ios swift fonts external
add a comment |
up vote
0
down vote
favorite
How to use non-bundle custom fonts in my iOS Application? I want to add font to app via iCloud or from internet and use it inside.
ios swift fonts external
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How to use non-bundle custom fonts in my iOS Application? I want to add font to app via iCloud or from internet and use it inside.
ios swift fonts external
How to use non-bundle custom fonts in my iOS Application? I want to add font to app via iCloud or from internet and use it inside.
ios swift fonts external
ios swift fonts external
asked Nov 11 at 12:30
Ihor M.
1155
1155
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Yes you can do this via
CTFontManagerRegisterGraphicsFont
(https://developer.apple.com/documentation/coretext/1499499-ctfontmanagerregistergraphicsfon)
You only need a reference to a file or data reference. The code should be self-explained:
guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
fatalError("[UIFont] Could not get data of font")
}
guard let dataProvider = CGDataProvider(data: fontData) else {
fatalError("[UIFont] Could not get dataprovider of font")
}
guard let fontRef = CGFont(dataProvider) else {
fatalError("[UIFont] Could not create font")
}
var errorRef: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) == false {
fatalError("[UIFont] Could not register font")
}
Then you can access the font over its name, like it were in the bundle.
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Yes you can do this via
CTFontManagerRegisterGraphicsFont
(https://developer.apple.com/documentation/coretext/1499499-ctfontmanagerregistergraphicsfon)
You only need a reference to a file or data reference. The code should be self-explained:
guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
fatalError("[UIFont] Could not get data of font")
}
guard let dataProvider = CGDataProvider(data: fontData) else {
fatalError("[UIFont] Could not get dataprovider of font")
}
guard let fontRef = CGFont(dataProvider) else {
fatalError("[UIFont] Could not create font")
}
var errorRef: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) == false {
fatalError("[UIFont] Could not register font")
}
Then you can access the font over its name, like it were in the bundle.
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
add a comment |
up vote
2
down vote
accepted
Yes you can do this via
CTFontManagerRegisterGraphicsFont
(https://developer.apple.com/documentation/coretext/1499499-ctfontmanagerregistergraphicsfon)
You only need a reference to a file or data reference. The code should be self-explained:
guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
fatalError("[UIFont] Could not get data of font")
}
guard let dataProvider = CGDataProvider(data: fontData) else {
fatalError("[UIFont] Could not get dataprovider of font")
}
guard let fontRef = CGFont(dataProvider) else {
fatalError("[UIFont] Could not create font")
}
var errorRef: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) == false {
fatalError("[UIFont] Could not register font")
}
Then you can access the font over its name, like it were in the bundle.
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Yes you can do this via
CTFontManagerRegisterGraphicsFont
(https://developer.apple.com/documentation/coretext/1499499-ctfontmanagerregistergraphicsfon)
You only need a reference to a file or data reference. The code should be self-explained:
guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
fatalError("[UIFont] Could not get data of font")
}
guard let dataProvider = CGDataProvider(data: fontData) else {
fatalError("[UIFont] Could not get dataprovider of font")
}
guard let fontRef = CGFont(dataProvider) else {
fatalError("[UIFont] Could not create font")
}
var errorRef: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) == false {
fatalError("[UIFont] Could not register font")
}
Then you can access the font over its name, like it were in the bundle.
Yes you can do this via
CTFontManagerRegisterGraphicsFont
(https://developer.apple.com/documentation/coretext/1499499-ctfontmanagerregistergraphicsfon)
You only need a reference to a file or data reference. The code should be self-explained:
guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
fatalError("[UIFont] Could not get data of font")
}
guard let dataProvider = CGDataProvider(data: fontData) else {
fatalError("[UIFont] Could not get dataprovider of font")
}
guard let fontRef = CGFont(dataProvider) else {
fatalError("[UIFont] Could not create font")
}
var errorRef: Unmanaged<CFError>?
if CTFontManagerRegisterGraphicsFont(fontRef, &errorRef) == false {
fatalError("[UIFont] Could not register font")
}
Then you can access the font over its name, like it were in the bundle.
answered Nov 11 at 12:57
messeb
17118
17118
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
add a comment |
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
Thank you so much! This is exactly what I was looking for
– Ihor M.
Nov 16 at 14:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248776%2fnon-bundle-external-fonts-for-ios-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown