Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom font into imglyKit SDK in iOS with Swift?

I have tried the following code for adding custom fonts into imglyKit SDK but no custom font is added. I have also put .ttf file into info.plist file as a resource.

        let sampleImage = image.image

    let configuration = Configuration() { builder in
        FontImporter.init().importFonts()

        builder.configurePhotoEditorViewController({ (editPhotoOption) in

            editPhotoOption.allowedPhotoEditorActions = [.text]

            editPhotoOption.actionButtonConfigurationClosure = {cell, _ in

                cell.captionLabel.text = "Add Text"
                //cell.backgroundColor = UIColor.red
            }
            editPhotoOption.backgroundColor = UIColor.brown
            editPhotoOption.allowsPreviewImageZoom = false            
        })

        builder.configureToolStackController({ (toolStackOption) in

            toolStackOption.mainToolbarBackgroundColor = UIColor.red
            toolStackOption.secondaryToolbarBackgroundColor = UIColor.brown

        })

        builder.configureTextFontToolController({ (textFontToolOption) in

            var fontArray = [String]()
            fontArray = ["AlexBrush_Regular.ttf", "Arabella.ttf"]
            textFontToolOption.accessibilityElements = fontArray

            textFontToolOption.actionButtonConfigurationClosure = { cell, _ in
                cell.backgroundColor = UIColor.red
            }                
        })


        builder.configureTextToolController({ (textToolOption) in

            textToolOption.textViewConfigurationClosure = { label in

                label.textAlignment = NSTextAlignment.center
            }
        })
    }

    let photoEditViewController = PhotoEditViewController(photo: sampleImage!, configuration: configuration)



    let toolStackController = ToolStackController(photoEditViewController: photoEditViewController)
    toolStackController.delegate = self
    toolStackController.navigationController?.view.backgroundColor = UIColor.red
    present(toolStackController, animated: true, completion: nil)

please help me to add a custom font

I have also used FontImporter class to load custom font as per guide here http://static.photoeditorsdk.com/docs/ios/Classes/FontImporter.html Thanks...

like image 399
Subhash Khimani Avatar asked Nov 09 '22 05:11

Subhash Khimani


1 Answers

I've investigate this issue. Looks like importFonts() function is added only for internal usage. In case you'd like to add custom fonts you should ask imglyKit developers or you can swizzle availableFontsList method to add your custom fonts.

You can find this method in class InstanceFactory on GitHub. Class methods swizzling sample: Gist

like image 129
Timur Bernikovich Avatar answered Nov 14 '22 22:11

Timur Bernikovich