Skip to content

Instantly share code, notes, and snippets.

@crayment
Created February 4, 2019 16:59
Show Gist options
  • Save crayment/8d9e9b97796b42e98d1d0a9ac5622bc8 to your computer and use it in GitHub Desktop.
Save crayment/8d9e9b97796b42e98d1d0a9ac5622bc8 to your computer and use it in GitHub Desktop.
import Foundation
import PlaygroundSupport
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.alignment = .center
stackView.axis = .vertical
stackView.spacing = 20
let label1 = UILabel()
label1.text = "مرحبًا. يرجى تسجيل الدخول أدناه للوصول إلى الدورات التدريبية الخاصة بك."
label1.numberOfLines = 0
stackView.addArrangedSubview(label1)
let textField = UITextField()
textField.borderStyle = .roundedRect
textField.placeholder = "اسم المستخدم"
stackView.addArrangedSubview(textField)
stackView.addArrangedSubview(UISwitch())
self.view.addSubview(stackView)
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20),
stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20),
stackView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 20),
textField.widthAnchor.constraint(equalTo: stackView.widthAnchor),
textField.heightAnchor.constraint(equalToConstant: 44)
])
}
}
let child = ViewController()
let container = UIViewController()
container.view.addSubview(child.view)
child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
child.view.frame = container.view.bounds
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