LoginSignup
4
5

More than 5 years have passed since last update.

MBProgress HUDでアニメーションgifを使う

Last updated at Posted at 2017-05-23

iOSのインジケータとしてお馴染みのMBProgressHUDですが、
customViewにアニメーションgifをどう使えば良いかわからなかったのでメモ。

1.ライブラリを追加

MBProgressHUD
FLAnimatedImage

下記を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。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5