简体   繁体   中英

UIColor dark mode backwards compatibility

I got lots of labels which have the color set to black. With the upcoming of dark mode, they should switch to an other color, since else they will be invisible. With SwiftUI , I thought this goes automatically when setting the Color property to primary .

Is there such thing for UIColor ? This label will be invisible in dark mode:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let label = UILabel(frame: .zero)

        label.text = "some text"
        label.textColor = .black

        view.addSubview(label)
        label.translatesAutoresizingMaskIntoConstraints = false

        label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        label.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
}

I can make lots and lots and lots of if statements to handle it, but is there an automatic UIColor property which will switch to the appropriate state?

你可以看一下UIColor.label

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM