简体   繁体   中英

Swift: how to create FDWaveformview Dynamically

I want to show wave of multiple audios in scrollview using swift4 and xcode 9. I am using cocoapos library FDWaveFormView for showing wave of audio file. For this I have to create fdwaveformview dynamically. Fdwaveformview works fine if I create this in story board. But it shows an error when create dynamically in swift class.

Code:

for index in selectedAudios {

  audioQueue.append(AVPlayerItem(url: index as! URL))
  print("aduio url: \(index)")

  let waveForm = FDWaveformView(frame: CGRect(x: 0, y: 0, width: 300, height: 150)) // error
  audio_scroll_view.addSubview(waveForm!)
}


Screen Shot Of Error

屏幕截图

Error: FDWaveformView initializer is inaccessible due to 'internal' protection level

Solution:

let frame = CGRect(x: 0, y: 0, width: 300, height: 100)
let waveform = FDWaveformView()
waveform.frame = frame
audio_scroll_view.addSubview(waveform)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM