How to add custom font to imglyKit SDK in iOS using Swift?

I tried the following code to add custom fonts to the imglyKit SDK, but did not add a custom font. I also put the .ttf file in the 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 add custom font

I also used the FontImporter class to load a custom font according to the manual here http://static.photoeditorsdk.com/docs/ios/Classes/FontImporter.html Thanks ...

+5
source share
1 answer

I am investigating this problem. It looks like the importFonts() function is importFonts() added for internal use only. If you want to add custom fonts, you should ask imglyKit developers or you can swizzle availableFontsList to add your custom fonts.

This method can be found in the InstanceFactory class on GitHub . Swizzling sample method class: Gist

+1
source

Source: https://habr.com/ru/post/1260633/


All Articles