2 // HomeViewController.swift
5 // Created by Ernest.lee on 17/10/2019.
6 // Copyright © 2019 Ernest.lee. All rights reserved.
13 public extension UIView {
15 case Left, Right, Top, Bottom
17 func addBorder(toSide side: ViewSide, withColor color: CGColor, andThickness thickness: CGFloat) {
19 let border = CALayer()
20 border.backgroundColor = color
23 case .Left: border.frame = CGRect(x: frame.minX, y: frame.minY, width: thickness, height: frame.height); break
24 case .Right: border.frame = CGRect(x: frame.maxX, y: frame.minY, width: thickness, height: frame.height); break
25 case .Top: border.frame = CGRect(x: frame.minX, y: frame.minY, width: frame.width, height: thickness); break
26 case .Bottom: border.frame = CGRect(x: frame.minX, y: frame.maxY, width: frame.width, height: thickness); break
29 layer.addSublayer(border)
31 func anchor(top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?,
32 paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat,
33 width: CGFloat, height: CGFloat, enableInsets: Bool) {
34 var topInset = CGFloat(0)
35 var bottomInset = CGFloat(0)
37 if #available(iOS 11, *), enableInsets {
38 let insets = self.safeAreaInsets
40 bottomInset = insets.bottom
45 translatesAutoresizingMaskIntoConstraints = false
48 self.topAnchor.constraint(equalTo: top, constant: paddingTop+topInset).isActive = true
51 self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true
53 if let right = right {
54 rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = true
56 if let bottom = bottom {
57 bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom-bottomInset).isActive = true
60 heightAnchor.constraint(equalToConstant: height).isActive = true
63 widthAnchor.constraint(equalToConstant: width).isActive = true
69 HomeVC is the main controller, it is responsible for Nav bar control and setting up childVC
72 class HomeController: UIViewController{
77 let mapVC: GameViewController = GameViewController()
82 override func viewDidLoad() {
84 view.backgroundColor = .gray
98 // if let frame = nil {
99 // mapVC.view.frame = frame
102 view.addSubview(mapVC.view)
103 mapVC.didMove(toParent: self)
109 func setConstraints(){
111 mapVC.view.anchor(top: nil, left: nil,
112 bottom: nil, right: nil,
113 paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0, enableInsets: false)
114 if #available(iOS 11.0, *) {
115 mapVC.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
118 mapVC.view.addBorder(toSide: .Left, withColor: UIColor.black.cgColor, andThickness: 1.0)
127 extension HomeController {
129 navigationController?.navigationBar.barTintColor = .white
130 navigationController?.navigationBar.isTranslucent = true
131 navigationController?.navigationBar.backgroundColor = .white
134 let threeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "Image").withRenderingMode(.alwaysOriginal),
137 action: #selector(handleThree))
142 navigationItem.leftBarButtonItems = [threeButton]
146 //MARK: - Nav Bar Handler
149 @objc func handleThree(){
150 //delegate?.handleThreeToggle()