ViewControllerExtensions.swift
2.52 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
44
45
46
47
48
49
50
51
//
// ViewControllerExtensions.swift
// WarplySDKFrameworkIOS
//
// Created by Manos Chorianopoulos on 5/5/22.
//
import UIKit
extension UIViewController {
func setBackButton() {
let uiscreen: CGRect = UIScreen.main.bounds
let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton
backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.025, height: uiscreen.height * 0.02)
backButton.imageView!.contentMode = .scaleAspectFit
//backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState())
backButton.setImage(UIImage(named: "ic_back"), for: .normal)
// backButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0)
backButton.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside)
backButton.translatesAutoresizingMaskIntoConstraints = false
// Add width, height constraints
let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.025)
let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: uiscreen.height * 0.02)
NSLayoutConstraint.activate([heightContraints,widthContraints])
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton)
self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false)
self.navigationItem.title = ""
}
@objc func moveToBack(_ sender:UIButton){
self.navigationController?.popViewController(animated: true)
}
func setNavigationTitle(_ title: String) {
let uiscreen: CGRect = UIScreen.main.bounds
let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: uiscreen.width * 0.7, height: uiscreen.height * 0.03))
titleLabel.text = title
titleLabel.textColor = UIColor(red: 0.21, green: 0.32, blue: 0.41, alpha: 1.00)
titleLabel.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium)
titleLabel.adjustsFontSizeToFitWidth = true
titleLabel.textAlignment = .center
self.navigationItem.titleView = titleLabel
}
}