├── .gitignore ├── SKView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIActivityIndicatorView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIButton.playground ├── Contents.swift ├── Resources │ └── star@3x.png ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UICollectionView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIColor.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIDatePicker.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIImageView.playground ├── Contents.swift ├── Resources │ ├── Apple.jpg │ └── copyright.txt ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UILabel-AttributedString.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UILabel.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIPageControl.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIPickerView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIProgressView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIScrollView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UISegmentedControl.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UISlider.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIStepper.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UISwitch.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UITableView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UITextField-RightView.playground ├── Contents.swift ├── Resources │ └── magnify@3x.png ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UITextField.playground ├── Contents.swift ├── Resources │ └── magnify.png ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UITextView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── UIView.playground ├── Contents.swift ├── Sources │ └── SupportCode.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata ├── WKWebView.playground ├── Contents.swift ├── contents.xcplayground └── playground.xcworkspace │ └── contents.xcworkspacedata └── iPad ├── Rakefile ├── UIKit Playground.playgroundbook.zip └── book.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | xcuserdata 2 | xcshareddata 3 | .DS_Store 4 | *.xctimeline -------------------------------------------------------------------------------- /SKView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import SpriteKit 3 | import PlaygroundSupport 4 | 5 | class CircleScene : SKScene { 6 | 7 | let circle = SKShapeNode(circleOfRadius: 20) 8 | 9 | override init() { 10 | super.init(size: CGSize.zero) 11 | self.scaleMode = .resizeFill 12 | self.backgroundColor = .yellow 13 | self.circle.fillColor = .red 14 | self.circle.strokeColor = .clear 15 | self.addChild(circle) 16 | } 17 | 18 | required init?(coder aDecoder: NSCoder) { 19 | fatalError("init(coder:) has not been implemented") 20 | } 21 | 22 | override func didChangeSize(_ oldSize: CGSize) { 23 | circle.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2) 24 | } 25 | 26 | override func touchesEnded(_ touches: Set, with event: UIEvent?) { 27 | if let location = touches.first?.location(in: self) { 28 | nodeTapped(node: self.atPoint(location)) 29 | } 30 | } 31 | 32 | func nodeTapped(node : SKNode) { 33 | if node === circle { 34 | circle.run(SKAction.sequence([ 35 | SKAction.scale(by: 1.5, duration: 0.1), 36 | SKAction.scale(by: 1/1.4, duration: 0.2) 37 | ])) 38 | } 39 | } 40 | 41 | } 42 | 43 | class ViewController : UIViewController { 44 | 45 | override func loadView() { 46 | 47 | let view = SKView() 48 | view.presentScene(CircleScene()) 49 | 50 | self.view = view 51 | } 52 | 53 | } 54 | 55 | PlaygroundPage.current.liveView = ViewController() 56 | 57 | -------------------------------------------------------------------------------- /SKView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /SKView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SKView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIActivityIndicatorView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ActivityViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let activityView = UIActivityIndicatorView() 14 | activityView.color = .gray 15 | activityView.startAnimating() 16 | 17 | view.addSubview(activityView) 18 | 19 | // Layout 20 | 21 | activityView.translatesAutoresizingMaskIntoConstraints = false 22 | NSLayoutConstraint.activate([ 23 | activityView.centerXAnchor.constraint(equalTo: view.centerXAnchor), 24 | activityView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20) 25 | 26 | ]) 27 | 28 | self.view = view 29 | } 30 | 31 | } 32 | 33 | PlaygroundPage.current.liveView = ActivityViewController() -------------------------------------------------------------------------------- /UIActivityIndicatorView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIActivityIndicatorView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIActivityIndicatorView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIButton.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ButtonViewController : UIViewController { 5 | 6 | var counter = 0 7 | 8 | var label : UILabel! 9 | var button : UIButton! 10 | var starButton : UIButton! 11 | 12 | override func loadView() { 13 | 14 | // UI 15 | 16 | let view = UIView() 17 | view.backgroundColor = .white 18 | 19 | label = UILabel() 20 | 21 | button = UIButton(type: .system) 22 | button.setTitle("Increment", for: .normal) 23 | button.tintColor = .red 24 | button.addTarget(self, action: #selector(updateView), for: .touchUpInside) 25 | 26 | starButton = UIButton(type: .system) 27 | starButton.setImage(UIImage(named: "star"), for: .normal) 28 | starButton.addTarget(self, action: #selector(toggleStarred), for: .touchUpInside) 29 | 30 | view.addSubview(label) 31 | view.addSubview(button) 32 | view.addSubview(starButton) 33 | 34 | // Layout 35 | 36 | label.translatesAutoresizingMaskIntoConstraints = false 37 | button.translatesAutoresizingMaskIntoConstraints = false 38 | starButton.translatesAutoresizingMaskIntoConstraints = false 39 | NSLayoutConstraint.activate([ 40 | label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 41 | label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 42 | 43 | button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20), 44 | button.firstBaselineAnchor.constraint(equalTo: label.firstBaselineAnchor), 45 | 46 | starButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 47 | starButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20) 48 | ]) 49 | 50 | self.view = view 51 | 52 | self.starred = false 53 | updateView() 54 | } 55 | 56 | @objc func updateView() { 57 | counter += 1 58 | label.text = "Counter: \(counter)" 59 | } 60 | 61 | @objc func toggleStarred() { 62 | self.starred = !self.starred 63 | } 64 | 65 | var starred = false { 66 | didSet { 67 | starButton.tintColor = starred ? .orange : .gray 68 | } 69 | } 70 | 71 | } 72 | 73 | 74 | PlaygroundPage.current.liveView = ButtonViewController() 75 | -------------------------------------------------------------------------------- /UIButton.playground/Resources/star@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ralfebert/uikit-playground/dc7a495909211b6389aabc56e6032d9feaea4363/UIButton.playground/Resources/star@3x.png -------------------------------------------------------------------------------- /UIButton.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIButton.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIButton.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UICollectionView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class CollectionViewController : UICollectionViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | self.collectionView?.backgroundColor = .white 9 | self.collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "PlayCell") 10 | } 11 | 12 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 13 | return 2 14 | } 15 | 16 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 17 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PlayCell", for: indexPath) 18 | cell.backgroundColor = .green 19 | return cell 20 | } 21 | 22 | } 23 | 24 | PlaygroundPage.current.liveView = CollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) 25 | -------------------------------------------------------------------------------- /UICollectionView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UICollectionView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UICollectionView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIColor.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | // Color constants 4 | 5 | UIColor.black 6 | UIColor.darkGray 7 | UIColor.lightGray 8 | UIColor.white 9 | UIColor.gray 10 | UIColor.red 11 | UIColor.green 12 | UIColor.blue 13 | UIColor.cyan 14 | UIColor.yellow 15 | UIColor.magenta 16 | UIColor.orange 17 | UIColor.purple 18 | UIColor.brown 19 | UIColor.clear 20 | 21 | // Color by component value 22 | 23 | UIColor(white: 0.5, alpha: 1.0) 24 | UIColor(hue: 0.5, saturation: 0.4, brightness: 1.0, alpha: 1.0) 25 | UIColor(red: 0.6, green: 1.0, blue: 1.0, alpha: 1.0) 26 | 27 | // Color by hex value 28 | 29 | extension UIColor { 30 | convenience init(rgb: Int, alpha: CGFloat) { 31 | let r = CGFloat((rgb & 0xFF0000) >> 16)/255 32 | let g = CGFloat((rgb & 0xFF00) >> 8)/255 33 | let b = CGFloat(rgb & 0xFF)/255 34 | self.init(red: r, green: g, blue: b, alpha: alpha) 35 | } 36 | 37 | convenience init(rgb: Int) { 38 | self.init(rgb:rgb, alpha:1.0) 39 | } 40 | } 41 | 42 | UIColor(rgb: 0xff5410) 43 | 44 | -------------------------------------------------------------------------------- /UIColor.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to MyPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIColor.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIColor.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIDatePicker.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class DatePickerViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | view = UIView() 10 | view.backgroundColor = .white 11 | 12 | let datePicker = UIDatePicker() 13 | datePicker.datePickerMode = .date 14 | 15 | view.addSubview(datePicker) 16 | 17 | // Layout 18 | 19 | datePicker.translatesAutoresizingMaskIntoConstraints = false 20 | NSLayoutConstraint.activate([ 21 | datePicker.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 22 | datePicker.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 23 | datePicker.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20) 24 | ]) 25 | 26 | self.view = view 27 | } 28 | 29 | } 30 | 31 | PlaygroundPage.current.liveView = DatePickerViewController() -------------------------------------------------------------------------------- /UIDatePicker.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIDatePicker.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIDatePicker.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIImageView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ImageViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let image = UIImage(named: "Apple.jpg") 14 | let imageView = UIImageView(image: image) 15 | 16 | view.addSubview(imageView) 17 | 18 | // Layout 19 | 20 | imageView.translatesAutoresizingMaskIntoConstraints = false 21 | NSLayoutConstraint.activate([ 22 | imageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 23 | imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20) 24 | ]) 25 | 26 | self.view = view 27 | } 28 | 29 | } 30 | 31 | PlaygroundPage.current.liveView = ImageViewController() -------------------------------------------------------------------------------- /UIImageView.playground/Resources/Apple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ralfebert/uikit-playground/dc7a495909211b6389aabc56e6032d9feaea4363/UIImageView.playground/Resources/Apple.jpg -------------------------------------------------------------------------------- /UIImageView.playground/Resources/copyright.txt: -------------------------------------------------------------------------------- 1 | https://commons.wikimedia.org/wiki/File:Red_Apple.jpg 2 | https://commons.wikimedia.org/wiki/File:You_cant_eat_me!_(708107473).jpg 3 | https://commons.wikimedia.org/wiki/File:Apricot_fruit.jpg 4 | https://commons.wikimedia.org/wiki/File:Bananas_white_background.jpg 5 | https://commons.wikimedia.org/wiki/Cucumis_melo#/media/File:Cantaloupes.jpg -------------------------------------------------------------------------------- /UIImageView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIImageView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIImageView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UILabel-AttributedString.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class LabelViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let label = UILabel() 14 | 15 | let attributedString = NSAttributedString(string: "hello", attributes: [NSAttributedString.Key.underlineStyle : NSUnderlineStyle.single.rawValue, NSAttributedString.Key.foregroundColor : UIColor.red]) 16 | 17 | label.attributedText = attributedString 18 | 19 | view.addSubview(label) 20 | 21 | // Layout 22 | 23 | label.translatesAutoresizingMaskIntoConstraints = false 24 | NSLayoutConstraint.activate([ 25 | label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 26 | label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 27 | ]) 28 | 29 | self.view = view 30 | } 31 | 32 | } 33 | 34 | PlaygroundPage.current.liveView = LabelViewController() 35 | -------------------------------------------------------------------------------- /UILabel-AttributedString.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UILabel-AttributedString.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UILabel-AttributedString.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UILabel.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class LabelViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let label = UILabel() 14 | label.text = "Hello world!" 15 | 16 | view.addSubview(label) 17 | 18 | // Layout 19 | 20 | label.translatesAutoresizingMaskIntoConstraints = false 21 | NSLayoutConstraint.activate([ 22 | label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 23 | label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 24 | ]) 25 | 26 | self.view = view 27 | } 28 | 29 | } 30 | 31 | PlaygroundPage.current.liveView = LabelViewController() 32 | -------------------------------------------------------------------------------- /UILabel.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UILabel.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UILabel.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIPageControl.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class PageControlViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .gray 12 | 13 | let pageControl = UIPageControl() 14 | pageControl.numberOfPages = 3 15 | 16 | view.addSubview(pageControl) 17 | 18 | // Layout 19 | 20 | pageControl.translatesAutoresizingMaskIntoConstraints = false 21 | NSLayoutConstraint.activate([ 22 | pageControl.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 23 | pageControl.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 24 | pageControl.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), 25 | ]) 26 | 27 | self.view = view 28 | } 29 | 30 | } 31 | 32 | PlaygroundPage.current.liveView = PageControlViewController() -------------------------------------------------------------------------------- /UIPageControl.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIPageControl.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIPageControl.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIPickerView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class PickerData : NSObject, UIPickerViewDataSource, UIPickerViewDelegate { 5 | let fruits = ["Apple", "Orange", "Banana"] 6 | 7 | func numberOfComponents(in pickerView: UIPickerView) -> Int { 8 | return 1 9 | } 10 | 11 | func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 12 | return fruits.count 13 | } 14 | 15 | func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 16 | return fruits[row] 17 | } 18 | } 19 | 20 | let pickerData = PickerData() 21 | let pickerView = UIPickerView() 22 | pickerView.backgroundColor = .white 23 | pickerView.dataSource = pickerData 24 | pickerView.delegate = pickerData 25 | pickerView.reloadAllComponents() 26 | 27 | PlaygroundPage.current.liveView = pickerView 28 | -------------------------------------------------------------------------------- /UIPickerView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIPickerView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIPickerView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIProgressView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ProgressViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let progressView = UIProgressView(progressViewStyle: .default) 14 | progressView.progressTintColor = .red 15 | progressView.trackTintColor = .lightGray 16 | progressView.progress = 0.25 17 | 18 | view.addSubview(progressView) 19 | 20 | // Layout 21 | 22 | progressView.translatesAutoresizingMaskIntoConstraints = false 23 | NSLayoutConstraint.activate([ 24 | progressView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 25 | progressView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 26 | progressView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), 27 | ]) 28 | 29 | self.view = view 30 | } 31 | 32 | } 33 | 34 | PlaygroundPage.current.liveView = ProgressViewController() -------------------------------------------------------------------------------- /UIProgressView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIProgressView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIProgressView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIScrollView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ScrollingViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 5000, height: 5000)) 9 | contentView.backgroundColor = .green 10 | 11 | let scrollView = UIScrollView() 12 | scrollView.contentSize = contentView.frame.size 13 | scrollView.addSubview(contentView) 14 | scrollView.flashScrollIndicators() 15 | scrollView.backgroundColor = .white 16 | 17 | self.view = scrollView 18 | } 19 | 20 | } 21 | 22 | PlaygroundPage.current.liveView = ScrollingViewController() -------------------------------------------------------------------------------- /UIScrollView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIScrollView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIScrollView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UISegmentedControl.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class SegmentsViewController : UIViewController { 5 | 6 | let items = ["A", "B", "C"] 7 | 8 | var label : UILabel! 9 | var segments : UISegmentedControl! 10 | 11 | override func loadView() { 12 | 13 | // UI 14 | 15 | let view = UIView() 16 | view.backgroundColor = .white 17 | 18 | label = UILabel() 19 | 20 | segments = UISegmentedControl(items: items) 21 | segments.addTarget(self, action: #selector(updateView), for: .valueChanged) 22 | 23 | view.addSubview(label) 24 | view.addSubview(segments) 25 | 26 | // Layout 27 | 28 | label.translatesAutoresizingMaskIntoConstraints = false 29 | segments.translatesAutoresizingMaskIntoConstraints = false 30 | NSLayoutConstraint.activate([ 31 | segments.centerXAnchor.constraint(equalTo: view.centerXAnchor), 32 | segments.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 33 | 34 | label.topAnchor.constraint(equalTo: segments.bottomAnchor, constant: 20), 35 | label.centerXAnchor.constraint(equalTo: segments.centerXAnchor), 36 | 37 | ]) 38 | 39 | self.view = view 40 | 41 | updateView() 42 | } 43 | 44 | @objc func updateView() { 45 | let idx = segments.selectedSegmentIndex 46 | let current = (idx == UISegmentedControl.noSegment) ? "none" : items[idx] 47 | label.text = "Current segment: \(current)" 48 | } 49 | 50 | } 51 | 52 | 53 | PlaygroundPage.current.liveView = SegmentsViewController() 54 | -------------------------------------------------------------------------------- /UISegmentedControl.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UISegmentedControl.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UISegmentedControl.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UISlider.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class SliderViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let slider = UISlider() 14 | slider.minimumValue = 10 15 | slider.maximumValue = 100 16 | 17 | view.addSubview(slider) 18 | 19 | // Layout 20 | 21 | slider.translatesAutoresizingMaskIntoConstraints = false 22 | NSLayoutConstraint.activate([ 23 | slider.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 24 | slider.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 25 | slider.widthAnchor.constraint(equalToConstant: 200) 26 | ]) 27 | 28 | 29 | self.view = view 30 | } 31 | 32 | } 33 | 34 | PlaygroundPage.current.liveView = SliderViewController() 35 | -------------------------------------------------------------------------------- /UISlider.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UISlider.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UISlider.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIStepper.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class StepperViewController : UIViewController { 5 | 6 | var label : UILabel! 7 | var stepper : UIStepper! 8 | 9 | override func loadView() { 10 | 11 | // UI 12 | 13 | let view = UIView() 14 | view.backgroundColor = .white 15 | 16 | label = UILabel() 17 | 18 | stepper = UIStepper() 19 | stepper.tintColor = .red 20 | stepper.addTarget(self, action: #selector(updateView), for: .valueChanged) 21 | stepper.value = 15 22 | stepper.minimumValue = -100 23 | stepper.maximumValue = 100 24 | stepper.stepValue = 5 25 | 26 | view.addSubview(label) 27 | view.addSubview(stepper) 28 | 29 | // Layout 30 | 31 | label.translatesAutoresizingMaskIntoConstraints = false 32 | stepper.translatesAutoresizingMaskIntoConstraints = false 33 | NSLayoutConstraint.activate([ 34 | label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 35 | label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 36 | 37 | stepper.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20), 38 | stepper.centerYAnchor.constraint(equalTo: label.centerYAnchor), 39 | ]) 40 | 41 | self.view = view 42 | 43 | updateView() 44 | } 45 | 46 | @objc func updateView() { 47 | label.text = "Counter: \(Int(stepper.value))" 48 | } 49 | 50 | } 51 | 52 | 53 | PlaygroundPage.current.liveView = StepperViewController() 54 | -------------------------------------------------------------------------------- /UIStepper.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIStepper.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIStepper.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UISwitch.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class SwitchViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let uiswitch = UISwitch() 14 | uiswitch.isOn = true 15 | 16 | view.addSubview(uiswitch) 17 | 18 | // Layout 19 | 20 | uiswitch.translatesAutoresizingMaskIntoConstraints = false 21 | NSLayoutConstraint.activate([ 22 | uiswitch.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 23 | uiswitch.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 24 | ]) 25 | 26 | self.view = view 27 | } 28 | 29 | } 30 | 31 | PlaygroundPage.current.liveView = SwitchViewController() 32 | -------------------------------------------------------------------------------- /UISwitch.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UISwitch.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UISwitch.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UITableView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class TableViewController : UITableViewController { 5 | 6 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 7 | return 2 8 | } 9 | 10 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 11 | let cell = UITableViewCell(style: .default, reuseIdentifier: nil) 12 | cell.textLabel?.text = "Cell \(indexPath.section).\(indexPath.row)" 13 | return cell 14 | } 15 | 16 | override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 17 | return "Section \(section)" 18 | } 19 | 20 | } 21 | 22 | let tableViewController = TableViewController(style: .plain) 23 | 24 | PlaygroundPage.current.liveView = tableViewController -------------------------------------------------------------------------------- /UITableView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UITableView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UITableView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UITextField-RightView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class TextFieldViewController : UIViewController, UITextFieldDelegate { 5 | 6 | var textFieldWithButton : UITextField! 7 | var textFieldWithActivity : UITextField! 8 | 9 | override func loadView() { 10 | 11 | // UI 12 | 13 | let view = UIView() 14 | view.backgroundColor = .white 15 | 16 | // Text Field with Button 17 | 18 | textFieldWithButton = UITextField() 19 | textFieldWithButton.borderStyle = .roundedRect 20 | textFieldWithButton.text = "Text Field with Button" 21 | 22 | let buttonImage = UIImage(named: "magnify")! 23 | let button = UIButton(type: .system) 24 | button.setImage(buttonImage, for: .normal) 25 | button.sizeToFit() 26 | 27 | textFieldWithButton.rightView = button 28 | textFieldWithButton.rightViewMode = .always 29 | view.addSubview(textFieldWithButton) 30 | 31 | // Text Field with Activity 32 | 33 | let activityIndicator = UIActivityIndicatorView() 34 | activityIndicator.style = .gray 35 | activityIndicator.startAnimating() 36 | activityIndicator.sizeToFit() 37 | activityIndicator.bounds.size.width += 10 38 | 39 | textFieldWithActivity = UITextField() 40 | textFieldWithActivity.borderStyle = .roundedRect 41 | textFieldWithActivity.text = "Active Text Field" 42 | 43 | view.addSubview(textFieldWithActivity) 44 | 45 | textFieldWithActivity.rightView = activityIndicator 46 | textFieldWithActivity.rightViewMode = .always 47 | view.addSubview(textFieldWithButton) 48 | 49 | self.view = view 50 | 51 | // Layout 52 | 53 | textFieldWithButton.translatesAutoresizingMaskIntoConstraints = false 54 | textFieldWithActivity.translatesAutoresizingMaskIntoConstraints = false 55 | let margins = view.layoutMarginsGuide 56 | NSLayoutConstraint.activate([ 57 | textFieldWithButton.topAnchor.constraint(equalTo: margins.topAnchor, constant: 20), 58 | textFieldWithButton.leadingAnchor.constraint(equalTo: margins.leadingAnchor), 59 | textFieldWithButton.trailingAnchor.constraint(equalTo: margins.trailingAnchor), 60 | 61 | textFieldWithActivity.leadingAnchor.constraint(equalTo: textFieldWithButton.leadingAnchor), 62 | textFieldWithActivity.trailingAnchor.constraint(equalTo: textFieldWithButton.trailingAnchor), 63 | textFieldWithActivity.topAnchor.constraint(equalTo: textFieldWithButton.bottomAnchor, constant: 10), 64 | ]) 65 | 66 | } 67 | 68 | } 69 | 70 | PlaygroundPage.current.liveView = TextFieldViewController() 71 | -------------------------------------------------------------------------------- /UITextField-RightView.playground/Resources/magnify@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ralfebert/uikit-playground/dc7a495909211b6389aabc56e6032d9feaea4363/UITextField-RightView.playground/Resources/magnify@3x.png -------------------------------------------------------------------------------- /UITextField-RightView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UITextField-RightView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UITextField-RightView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UITextField.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class TextFieldViewController : UIViewController, UITextFieldDelegate { 5 | 6 | var label : UILabel! 7 | var textField : UITextField! 8 | 9 | override func loadView() { 10 | 11 | // UI 12 | 13 | let view = UIView() 14 | view.backgroundColor = .white 15 | 16 | textField = UITextField() 17 | textField.borderStyle = .roundedRect 18 | textField.text = "Hello world!" 19 | view.addSubview(textField) 20 | 21 | label = UILabel() 22 | view.addSubview(label) 23 | 24 | self.view = view 25 | 26 | // Layout 27 | 28 | textField.translatesAutoresizingMaskIntoConstraints = false 29 | label.translatesAutoresizingMaskIntoConstraints = false 30 | let margins = view.layoutMarginsGuide 31 | NSLayoutConstraint.activate([ 32 | textField.topAnchor.constraint(equalTo: margins.topAnchor, constant: 20), 33 | textField.leadingAnchor.constraint(equalTo: margins.leadingAnchor), 34 | textField.trailingAnchor.constraint(equalTo: margins.trailingAnchor), 35 | 36 | label.leadingAnchor.constraint(equalTo: textField.leadingAnchor), 37 | label.topAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10), 38 | ]) 39 | 40 | // Events 41 | 42 | textField.addTarget(self, action: #selector(updateLabel), for: UIControl.Event.editingChanged) 43 | 44 | updateLabel() 45 | } 46 | 47 | @objc func updateLabel() { 48 | self.label.text = textField.text 49 | } 50 | 51 | } 52 | 53 | PlaygroundPage.current.liveView = TextFieldViewController() 54 | -------------------------------------------------------------------------------- /UITextField.playground/Resources/magnify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ralfebert/uikit-playground/dc7a495909211b6389aabc56e6032d9feaea4363/UITextField.playground/Resources/magnify.png -------------------------------------------------------------------------------- /UITextField.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UITextField.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UITextField.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UITextView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class TextViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | let textView = UITextView() 9 | textView.text = "Hello World!\nHello Playground!" 10 | 11 | self.view = textView 12 | } 13 | 14 | } 15 | 16 | PlaygroundPage.current.liveView = TextViewController() -------------------------------------------------------------------------------- /UITextView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UITextView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UITextView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import PlaygroundSupport 3 | 4 | class ViewController : UIViewController { 5 | 6 | override func loadView() { 7 | 8 | // UI 9 | 10 | let view = UIView() 11 | view.backgroundColor = .white 12 | 13 | let innerView = UIView() 14 | innerView.backgroundColor = .yellow 15 | view.addSubview(innerView) 16 | 17 | let shadowView = UIView() 18 | shadowView.layer.masksToBounds = false 19 | shadowView.layer.shadowOffset = CGSize(width: 1, height: 1) 20 | shadowView.layer.shadowColor = UIColor.black.cgColor 21 | shadowView.layer.shadowRadius = 4 22 | shadowView.layer.shadowOpacity = 0.8 23 | shadowView.layer.cornerRadius = 5 24 | shadowView.backgroundColor = .red 25 | view.addSubview(shadowView) 26 | 27 | // Layout 28 | 29 | shadowView.translatesAutoresizingMaskIntoConstraints = false 30 | innerView.translatesAutoresizingMaskIntoConstraints = false 31 | NSLayoutConstraint.activate([ 32 | innerView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), 33 | innerView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), 34 | innerView.widthAnchor.constraint(equalToConstant: 80), 35 | innerView.heightAnchor.constraint(equalToConstant: 80), 36 | 37 | shadowView.topAnchor.constraint(equalTo: innerView.bottomAnchor, constant: 20), 38 | shadowView.leadingAnchor.constraint(equalTo: innerView.leadingAnchor), 39 | shadowView.widthAnchor.constraint(equalToConstant: 80), 40 | shadowView.heightAnchor.constraint(equalToConstant: 80) 41 | ]) 42 | 43 | self.view = view 44 | } 45 | 46 | } 47 | 48 | PlaygroundPage.current.liveView = ViewController() -------------------------------------------------------------------------------- /UIView.playground/Sources/SupportCode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to UIKitPlayground.playground. 3 | // 4 | -------------------------------------------------------------------------------- /UIView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WKWebView.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | import WebKit 2 | import UIKit 3 | import PlaygroundSupport 4 | 5 | class WebViewController : UIViewController { 6 | 7 | override func loadView() { 8 | 9 | let webView = WKWebView() 10 | webView.loadHTMLString("Hello world", baseURL: nil) 11 | 12 | self.view = webView 13 | } 14 | 15 | } 16 | 17 | PlaygroundPage.current.liveView = WebViewController() 18 | -------------------------------------------------------------------------------- /WKWebView.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /WKWebView.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iPad/Rakefile: -------------------------------------------------------------------------------- 1 | task :default do 2 | 3 | Dir["../*.playground"].each do |playground| 4 | name = File.basename(playground, ".*") 5 | dir = "Chapter 1.playground/Pages/#{name}.xcplaygroundpage" 6 | FileUtils.mkdir_p(dir) 7 | FileUtils.cp(File.join(playground, "Contents.swift"), "#{dir}/Contents.swift") 8 | end 9 | 10 | system("playgroundbook render book.yaml") 11 | 12 | end -------------------------------------------------------------------------------- /iPad/UIKit Playground.playgroundbook.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ralfebert/uikit-playground/dc7a495909211b6389aabc56e6032d9feaea4363/iPad/UIKit Playground.playgroundbook.zip -------------------------------------------------------------------------------- /iPad/book.yaml: -------------------------------------------------------------------------------- 1 | name: UIKit Playground 2 | identifier: de.ralfebert.UICatalog 3 | deployment_target: ios10.0 # Optional 4 | swift_version: "4.0" 5 | imports: # Optional, defaults to UIKit 6 | - UIKit 7 | chapters: 8 | - name: Chapter 1 9 | edge_to_edge_live_view: false # defaults to true 10 | live_view_mode: "VisibleByDefault" # defaults to "HiddenByDefault" 11 | --------------------------------------------------------------------------------