Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created February 4, 2019 14:18
Show Gist options
  • Save mbrandonw/465ae3a165982f874cd690a090b042ca to your computer and use it in GitHub Desktop.
Save mbrandonw/465ae3a165982f874cd690a090b042ca to your computer and use it in GitHub Desktop.
import Foundation
import PlaygroundSupport
import UIKit
class VC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
self.view.translatesAutoresizingMaskIntoConstraints = false
let stackView = UIStackView()
stackView.distribution = .fillEqually
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .horizontal
let label1 = UILabel()
label1.text = "1"
label1.textColor = .black
label1.backgroundColor = .blue
stackView.addArrangedSubview(label1)
let label2 = UILabel()
label2.text = "2"
label2.backgroundColor = .red
label2.textColor = .black
stackView.addArrangedSubview(label2)
self.view.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
stackView.topAnchor.constraint(equalTo: self.view.topAnchor),
stackView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
])
}
}
let child = VC()
let container = UIViewController()
container.view.addSubview(child.view)
container.addChild(child)
container.setOverrideTraitCollection(
UITraitCollection(layoutDirection: .rightToLeft),
// UITraitCollection(layoutDirection: .leftToRight),
forChild: child
)
PlaygroundPage.current.liveView = container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment