-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathExampleBaseViewController.swift
More file actions
43 lines (36 loc) · 1.13 KB
/
ExampleBaseViewController.swift
File metadata and controls
43 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// ExampleBaseViewController.swift
// HeroExamples
//
// Created by Luke Zhao on 2018-04-15.
// Copyright © 2018 Luke Zhao. All rights reserved.
//
import UIKit
// basically a view controller with a back button and a tap gesture configured
class ExampleBaseViewController: UIViewController {
let dismissButton = UIButton(type: .system)
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 13.0, tvOS 13, *) {
view.backgroundColor = .systemBackground
} else {
view.backgroundColor = .white
}
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(onTap)))
dismissButton.setTitle("Back", for: .normal)
dismissButton.addTarget(self, action: #selector(back), for: .touchUpInside)
dismissButton.hero.id = "back button"
view.addSubview(dismissButton)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
dismissButton.sizeToFit()
dismissButton.center = CGPoint(x: 30, y: 30)
}
@objc func back() {
dismiss(animated: true, completion: nil)
}
@objc func onTap() {
back() // default action is back on tap
}
}