LoginSignup
0
0

More than 5 years have passed since last update.

バージョンアップへの対応備忘録

Posted at

podでインストールしたライブラリーのアップデート

ターミナルで該当のディレクトリまで行き、そこでpodのインストールを行う。


pod install

たまに、podでインストールすることができない場合があるから、その場合はcocoapod自体のアップデートを行う。

参照

ファイルの初期設定部分

    /*
    *  インスタンス化された直後(初回に一度のみ)
    */
    override func viewDidLoad() {
    }
    /*
     *  画面が表示される直前
     */
    override func viewWillAppear(_ animated: Bool) {
    }
    /*
     *  画面が表示された直後
     */
    override func viewDidAppear(_ animated: Bool) {
    }
    /*
     *  別画面に遷移する直前
     */
    override func viewWillDisappear(_ animated: Bool) {
    }

 UIButtonの画像の設定方法

罫線も周りにひいてボタンぽくする

{
       didSet {
           downloadButton.setImage(UIImage(named: "download")?.withRenderingMode(.alwaysTemplate), for:.normal)
           downloadButton.tintColor = UIColor(red: 131/255, green: 171/255, blue: 179/255, alpha: 1)
           downloadButton.layer.width = 1
           downloadButton.layer.Color = UIColor(red: 131/255, green: 171/255, blue: 179/255, alpha: 1)
           downloadButton.cornerRadius = 14
           downloadButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentleft;
           downloadButton.contentEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
       }
   }

参考:https://stackoverflow.com/questions/2765024/how-to-set-the-title-of-uibutton-as-left-alignment
http://mzgk.github.io/blog/2014/uibutton-title-align/

共通のカラーをクラス化する

参照:https://qiita.com/ShinokiRyosei/items/f6873902659fe77e3d9d

UIImageの画像の色を変更する

    @IBOutlet fileprivate weak var playingImage: UIImageView! {
        didSet {
            playingImage.image = UIImage(named: "playing")?.withRenderingMode(.alwaysTemplate)
            playingImage.tintColor = ColorManager().highRed()
        }
    }

セッティングによる条件の振り分け

        // コンパクトコントローラー:朗読設定
        readSettingButton.rx.tap.asDriver()
            .drive(onNext: { [weak self] in
                let setting = AudioPlayService.shared.setting
                if setting != .repeat {
                    AudioPlayService.shared.setting = .repeat
                    self?.readSettingButton.tintColor = UIColor(red: 232/255, green: 30/255, blue: 136/255, alpha: 1.0)
                } else {
                    AudioPlayService.shared.setting = .autoNextPlay
                    self?.readSettingButton.tintColor = UIColor(red: 131/255, green: 171/255, blue: 179/255, alpha: 1.0)
                }
            })
        .disposed(by: disposeBag)

画面を遷移させる方法

        // コンパクトコントローラー:設定ボタン
        soundSetButton.rx.tap.asDriver()
            .drive(onNext: { [weak self] in
                let controller = ModalViewController.instantiate()
                self?.navigationController?.pushViewController(controller, animated: true)
            })
            .disposed(by: disposeBag)

画面が遷移できない場合

Storybordのclass指定の下のフォームをnoneからアプリを選択する必要がある。
参照:https://qiita.com/eidera/items/f6fd3b1088d7bd6fe523

ナビゲーションの戻るボタンのイメージを変更させる

        UINavigationBar.appearance().backIndicatorImage = UIImage(named: "backItem")
        UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "backItem")

Bottom Bar Itemの表示/非表示

Bottom Bar Itemの設定には、遷移元の画面と遷移後の画面で設定する必要がある。

ナビゲーションの「戻る」ボタンを設定

    override func viewDidLoad() {
        self.navigationController?.navigationBar.backItem?.title = ""
        super.viewDidLoad()
        bindViewModels()
    }

BackButtonのタイトル設定

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBar.topItem?.title = "タイトルテキスト"
        }

画面のタイトルを設定

self.navigationItem.title = book.title

SVProgressHUDのSwift4対応

Swift3の場合は以下の書き方

SVProgressHUD.show(with: .gradient)

Swift4の時は次のように書き換える

        SVProgressHUD.setDefaultMaskType(.gradient)
        SVProgressHUD.show()

NSAttributedStringの変更

旧:NSFontAttributeName
新:NSAttributedStringKey.font

旧:NSForegroundColorAttributeName
新:NSAttributedStringKey.foregroundColor

参考:https://medium.com/swift-column/swift-3-to-4-2c8bf389761a

0
0
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
0
0