Showing
1 changed file
with
12 additions
and
8 deletions
... | @@ -8,18 +8,21 @@ | ... | @@ -8,18 +8,21 @@ |
8 | import UIKit | 8 | import UIKit |
9 | 9 | ||
10 | extension UIViewController { | 10 | extension UIViewController { |
11 | - func setBackButton(_ icon:String = "ic_back") { | 11 | + func setBackButton(_ icon:String = "ic_back_2") { |
12 | let uiscreen: CGRect = UIScreen.main.bounds | 12 | let uiscreen: CGRect = UIScreen.main.bounds |
13 | 13 | ||
14 | let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton | 14 | let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton |
15 | if (icon == "ic_close_2") { | 15 | if (icon == "ic_close_2") { |
16 | - backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.035, height: uiscreen.height * 0.035) | 16 | + backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18) |
17 | } else { | 17 | } else { |
18 | - backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.035, height: uiscreen.height * 0.03) | 18 | + backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18) |
19 | } | 19 | } |
20 | +// backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.01, height: uiscreen.height * 0.01) | ||
21 | + // backButton.backgroundColor = .red | ||
20 | backButton.imageView!.contentMode = .scaleAspectFit | 22 | backButton.imageView!.contentMode = .scaleAspectFit |
21 | //backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState()) | 23 | //backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState()) |
22 | - backButton.setImage(UIImage(named: icon, in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal) | 24 | +// backButton.setImage(UIImage(named: icon), for: .normal) |
25 | + backButton.setBackgroundImage(UIImage(named: icon), for: .normal) | ||
23 | // backButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0) | 26 | // backButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0) |
24 | backButton.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside) | 27 | backButton.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside) |
25 | 28 | ||
... | @@ -27,16 +30,17 @@ extension UIViewController { | ... | @@ -27,16 +30,17 @@ extension UIViewController { |
27 | backButton.translatesAutoresizingMaskIntoConstraints = false | 30 | backButton.translatesAutoresizingMaskIntoConstraints = false |
28 | // Add width, height constraints | 31 | // Add width, height constraints |
29 | if (icon == "ic_close_2") { | 32 | if (icon == "ic_close_2") { |
30 | - 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.035) | 33 | + let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18) |
31 | - 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.035) | 34 | + let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18) |
32 | NSLayoutConstraint.activate([heightContraints,widthContraints]) | 35 | NSLayoutConstraint.activate([heightContraints,widthContraints]) |
33 | } else { | 36 | } else { |
34 | - 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.035) | 37 | + let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18) |
35 | - 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.03) | 38 | + let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18) |
36 | NSLayoutConstraint.activate([heightContraints,widthContraints]) | 39 | NSLayoutConstraint.activate([heightContraints,widthContraints]) |
37 | } | 40 | } |
38 | 41 | ||
39 | let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton) | 42 | let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton) |
43 | + NSLayoutConstraint.activate([(leftBarButtonItem.customView!.widthAnchor.constraint(equalToConstant: 18)),(leftBarButtonItem.customView!.heightAnchor.constraint(equalToConstant: 18))]) | ||
40 | self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false) | 44 | self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false) |
41 | self.navigationItem.title = "" | 45 | self.navigationItem.title = "" |
42 | 46 | ... | ... |
-
Please register or login to post a comment