LoginSignup
2
3

More than 3 years have passed since last update.

SVProgressHUDのimageにtintColorを反映させないようにする

Last updated at Posted at 2020-12-08

追記(2020/12/11)

最新のmasterブランチではimageColorとtextColorの対応が反映されてました。
ので、バージョン管理がされてない場合は:gitでmasterからinstallするようにすれば解決です。

はじめに

Qiita Advent Calendar 2020 Swift 9日目のエントリーです。

すみません、色々考えたんですが大したこと思いつかなかったので最近やったことについて。

SVProgressHUD

業務でローディングダイアログを実装する際にSVProgressHUDを利用しました。

特にアニメーションの指定などなく、基本的なものでよかったのでほぼ問題なかったんですが
そのまま利用するとtintColorがimageViewにもかかって、画像をそのまま利用しつつ文字色を別のものに変えるというのができませんでした。(※できるのかもしれないのですが、自分ではわかりませんでした。。)

なのでforkしてtintColorを画像に反映されないように修正して使用しました。

Screen Shot 2020-12-08 at 13.14.25.png

修正内容

僕の場合はそのあと画像に色を設定する必要がなかったので
「strongSelf.imageView.tintColor = strongSelf.foregroundImageColorForStyle;」
を適用させないようにif文をざっくり削除しました。
画像にもかけたいケースもある場合は分岐の条件を変更させたり必要だと思います。

SVProgressHUD.m
if (self.shouldTintImages) {
    if (image.renderingMode != UIImageRenderingModeAlwaysTemplate) {
        strongSelf.imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    }
    strongSelf.imageView.tintColor = strongSelf.foregroundImageColorForStyle;
} else {
    strongSelf.imageView.image = image;
}

↓

strongSelf.imageView.image = image;

実際に使う側での設定

hoge.swift
// ダイアログを表示するのに使用
private var requesting: Bool = false {
     didSet {
        if requesting {
            //  R.string.localizable.progress_loading()->"読み込み中"
            SVProgressHUD.show(withStatus: R.string.localizable.progress_loading())
        } else {
            SVProgressHUD.dismiss()
        }
    }
}

private func setupSVProgressHUD() {
    SVProgressHUD.setForegroundImageColor(.primary)
    SVProgressHUD.setMinimumSize(CGSize(width: 150, height: 150))
    SVProgressHUD.setImageViewSize(CGSize(width: 60, height: 60))
    SVProgressHUD.setRingRadius(28)
    SVProgressHUD.setRingThickness(5)
    SVProgressHUD.setDefaultMaskType(.clear)
}
2
3
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
2
3