0

I would like to you use custom font in my app. I can change it almost everywhere. Except action sheets. How to do it?

I know how to change color using this code in SceneDelegate.swift:

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(Color.accentColor)

I cannot see anything font related in the methods list for this code.

My code for action sheet is this:

    Button(action: {
        self.showingActionSheet = true
    })
    {
        HStack {
            Text("Open Action Sheet")
        }
    }
    .actionSheet(isPresented: $showingActionSheet) {
        ActionSheet(title: Text("Title"), message: Text("message"), buttons: [
            .default(Text("Action 1")) {
                // Do something
            },
            .cancel()
        ])
    }
mallow
  • 2,368
  • 2
  • 22
  • 63
  • 2
    I don’t think it can be done. In UIKit you had to do it using private APIs which would cause Apple to reject your app when you submit it to the App Store. This [post](https://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color) has lots of answers for UIKit but all mention private APIs. Currently there is no way to do it in SwiftUI that I am aware of. Your best bet is writing your own alert/actionsheet so you can customise it as you want. – Andrew Apr 03 '21 at 08:53
  • Thanks @Andrew If so, I will probably live with default fonts for a while. WWDC is just around the corner. Maybe it will bring changes on that matter. If not, I will do the same you suggest - build a custom alert/actionsheet. – mallow Apr 03 '21 at 09:04

0 Answers0