2

So I downloaded the zip: https://github.com/hfg-gmuend/openmoji, opened it up, opened the font folder, and dragged the OpenMoji-Color.ttf file into my Xcode project, but then I realized it's not really a "font" that modifies existing text, so how exactly do I put the emojis inside of strings, or Images or something like that?

Normally, I'd do something like:

Text("")
    .font(Font.custom("OpenMoji-Color", size: 20))

Alternatively, I was hoping to do something like:

Image("") //somehow modify it to be in the correct OpenMoji style

Does anyone know how to do this?

nickcoding2
  • 142
  • 1
  • 8
  • 34
  • you should use real name of font rather than the file name of font come with – ios coder Apr 10 '21 at 13:35
  • @swiftPunk Right now, instead of ".ttfFileHere", I'm using "NotoColorEmoji"--I'm also just trying to modify an emoji inserted from Edit > Emojis and Symbols > Picking a random one, but it's not modifying the text, and I also don't know how to put the emoji inside an image – nickcoding2 Apr 10 '21 at 13:38
  • 1
    The [documentation](https://www.google.com/get/noto/help/emoji/) says the following about NotoColorEmoji: **This font format is supported on Android and Linux, but doesn’t work on macOS or Windows.** Though it doesn't explicitly say it, it probably won't work on iOS either. – Andrew Apr 10 '21 at 13:59
  • @Andrew Thank you, I think you might be right--I changed up my question so it's more general though. Now I'm trying to use OpenMoji-Color emojis in the same way, but it's still not working...any help would be appreciated :-) – nickcoding2 Apr 10 '21 at 14:12
  • The easiest way to check if the Mac can use the font is to try and install the font to FontBook. If it will install there then you can probably use it. When I tried to instal NotoColorEmoji it complained and said that it was not possible to install. It may be the same for OpenMoji-Color – Andrew Apr 10 '21 at 14:14
  • @Andrew It was able to validate/install fine in FontBook...really not sure why it's not updating the emoji in Xcode. Just wanted to note I also put the ttf file name inside the Fonts provided by application item in info.plist. – nickcoding2 Apr 10 '21 at 14:22
  • Here is an [answer](https://stackoverflow.com/questions/58864731/swiftui-wont-display-custom-font/58866233#58866233) I wrote previously on how to install and use a custom font in SwiftUI. I tried it with OpenMoji-Color, the font's name to use in your Swift code is **OpenMojiColor** however it just returns a b&w emoji for the entered emoji see the following screenshot https://i.stack.imgur.com/iqQSB.png it also has some extra spacing above the emoji – Andrew Apr 10 '21 at 14:46
  • @Andrew Yeah I have the same issue...not sure what to do with it honestly, and there's only so many free open source emoji ttf sets out there... – nickcoding2 Apr 10 '21 at 15:15

2 Answers2

1

I think the safest bet would be to load the specific ones you want to use as images. In the OpenMoji .zip file the .png files of all emojis are contained in file "color". You could drag them from there to your Xcode app bundle Assets folder.

After that you can directly load them by referencing to the image names (unicode in this case).

struct ContentView: View {
    var body: some View {
        Image("1F440")
    }
}

Alternatively if you have multiple ones you can make an array which holds all of your images and reference them from there.

struct ContentView: View {

    @State private var mojis = ["1F440", "1F1EA-1F1FA"]

    var body: some View {
        Image(mojis[1])
    }
 }
  • 1
    You don’t need the @State in the ContentView unless you are planning on changing the values contained within the array at runtime. – Andrew Apr 11 '21 at 06:51
0

This solution will work perfectly.

Text("")
        .font(.system(size: 60))