2016-12-01 95 views
5

我已經嘗試了以下代碼,將自定義字體添加到imglyKit SDK中,但未添加自定義字體。我還將.ttf文件作爲資源放入info.plist文件中。如何使用Swift將自定義字體添加到iOS中的imglyKit SDK中?

 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) 

請幫我添加自定義字體

我也用FontImporter類自定義字體爲每蒞臨指導http://static.photoeditorsdk.com/docs/ios/Classes/FontImporter.html 由於加載...

+0

您是否有示例項目? –

+0

是@TimurBernikowich –

+0

看看我的答案。 –

回答

1

我已經研究這個問題。看起來像importFonts()函數僅用於內部使用。如果您想添加自定義字體,您應該詢問imglyKit開發人員,或者您可以調配availableFontsList方法來添加自定義字體。

您可以在類InstanceFactory on GitHub中找到此方法。類方法swizzling示例:Gist

+0

availableFontsList屬性是隻讀的,我們不能指定值@TimurBernikowich –

+0

但是你可以調整getter方法,而沒有另一種方法@SubhashKhimani –

相關問題