LoginSignup
9
4

More than 5 years have passed since last update.

AssetsCatalogのColorSetをStoryboardで指定するとviewDidLoadで色が変更されない

Last updated at Posted at 2018-11-30

はじめに

表題の通りです。
ハマったので共有します。。。

現象

スクリーンショット 2018-11-30 20.13.56.png
スクリーンショット 2018-11-30 20.14.31.png

AssetsCatalogで作成したColorSetをstoryboardで指定します。
上記画像ではViewControllerのviewに作成した色を指定しています。

ViewController.swift
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.view.backgroundColor = .red
    }


}

viewDidLoadで背景色を赤に変更してみましたが、緑のままでした。。。

解決?

メインスレッドで非同期実行することで色の変更は出来ました。

ViewController.swift
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        DispatchQueue.main.async {
            self.view.backgroundColor = .red
        }
    }


}

さいごに

どなたか理由や対策をご存知の方がいらっしゃったら教えてください。。

コメントにて解説いただけました!ありがとうございました。
また、海外にもまとめている方がいらっしゃいました。
https://devblog.xero.com/managing-ui-colours-with-ios-11-asset-catalogs-16500ba48205

9
4
3

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
9
4