Advertisement
Don_Mag

Untitled

Aug 5th, 2022
917
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class LightDarkVC: UIViewController {
  2.    
  3.     override func viewDidLoad() {
  4.         super.viewDidLoad()
  5.        
  6.         let stack = UIStackView()
  7.         stack.axis = .vertical
  8.         stack.spacing = 20
  9.        
  10.         stack.translatesAutoresizingMaskIntoConstraints = false
  11.         view.addSubview(stack)
  12.        
  13.         let g = view.safeAreaLayoutGuide
  14.         NSLayoutConstraint.activate([
  15.             stack.topAnchor.constraint(equalTo: g.topAnchor, constant: 40.0),
  16.             stack.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 40.0),
  17.             stack.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -40.0),
  18.         ])
  19.  
  20.         let font: UIFont = .systemFont(ofSize: 24.0, weight: .bold)
  21.         var v: UILabel!
  22.        
  23.         v = UILabel()
  24.         v.text = "Default"
  25.         v.textAlignment = .center
  26.         v.font = font
  27.         stack.addArrangedSubview(v)
  28.  
  29.         v = UILabel()
  30.         v.text = "Always Light"
  31.         v.textAlignment = .center
  32.         v.overrideUserInterfaceStyle = .light
  33.         v.font = font
  34.         stack.addArrangedSubview(v)
  35.        
  36.         v = UILabel()
  37.         v.text = "Always Dark"
  38.         v.textAlignment = .center
  39.         v.overrideUserInterfaceStyle = .dark
  40.         v.font = font
  41.         stack.addArrangedSubview(v)
  42.        
  43.         v = UILabel()
  44.         v.text = "Explicit Colors\nWhite Background\nBlack .textColor"
  45.         v.textAlignment = .center
  46.         v.numberOfLines = 0
  47.         v.backgroundColor = .white
  48.         v.textColor = .black
  49.         v.font = font
  50.         stack.addArrangedSubview(v)
  51.        
  52.     }
  53.    
  54. }
  55.  
Advertisement
RAW Paste Data Copied
Advertisement