iOSのインジケータとしてお馴染みのMBProgressHUDですが、
customViewにアニメーションgifをどう使えば良いかわからなかったのでメモ。
1.ライブラリを追加
下記をPodfileに追記し、pod install
します。
pod 'MBProgressHUD', '~> 1.0.0'
pod 'FLAnimatedImage', '~> 1.0'
2.MPBrogressHUDをカスタマイズして表示
// インジケータを作成
let hud = MBProgressHUD.showAdded(to: view, animated: true)
// imageViewにアニメーションgifの読み込み
let filePath = URL(fileURLWithPath: Bundle.main.path(forResource: "ファイル名", ofType: "gif")!)
let image = FLAnimatedImage(animatedGIFData: NSData(contentsOf: filePath)! as Data)
let imageView = FLAnimatedImageView()
imageView.animatedImage = image
// インジケータにアニメーションgifを読み込んだimageViewをセット
hud.mode = .customView
hud.customView = imageView
// インジケータの背景を透明化
hud.bezelView.color = UIColor.clear
hud.bezelView.style = .solidColor
// インジケータを表示
hud.show(animated: true)
これでOK。