Ask Your Question
3

How can I include a font in my Xcode project through CMake?

asked 2023-06-10 02:59:57 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-10 03:02:01 +0000

plato gravatar image

To include a font in your Xcode project through CMake, follow these steps:

  1. Create a new directory in your project called Fonts and place your font file (.ttf, .otf, etc.) in that directory.

  2. In your CMakeLists.txt, create a variable that holds the path to your Fonts directory:

set(FONT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Fonts")
  1. Add the following lines of code to your CMakeLists.txt to copy the font file to your app bundle:
# Copy font to app bundle
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND
                    ${CMAKE_COMMAND} -E copy_directory ${FONT_DIR} ${APP_BUNDLE}/Contents/Resources)
  1. In your Xcode project, go to your app target and add the font file to the project by selecting "Add Files to [App Name]" from the File menu.

  2. Select the font file and set the target membership to your app target.

  3. In your app's Info.plist, add a new entry for the font file with the name of the file and the relative path to the Fonts directory:

<key>UIAppFonts</key>
<array>
    <string>MyFont.ttf</string>
</array>
  1. Build and run your app to see the font in action!
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-10 02:59:57 +0000

Seen: 15 times

Last updated: Jun 10 '23