Manos Chorianopoulos

fix back button image

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -9,39 +9,58 @@ import UIKit
extension UIViewController {
func setBackButton(_ icon:String = "ic_back_2") {
let uiscreen: CGRect = UIScreen.main.bounds
// let uiscreen: CGRect = UIScreen.main.bounds
let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton
if (icon == "ic_close_2") {
backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18)
} else {
backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18)
}
// backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.01, height: uiscreen.height * 0.01)
// backButton.backgroundColor = .red
backButton.imageView!.contentMode = .scaleAspectFit
//backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState())
// backButton.setImage(UIImage(named: icon), for: .normal)
backButton.setBackgroundImage(UIImage(named: icon), for: .normal)
// backButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0)
backButton.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside)
// let backButton = UIButton(type: UIButton.ButtonType.custom) as UIButton
// if (icon == "ic_close_2") {
// backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18)
// } else {
// backButton.frame = CGRect(x: 0, y: 0, width: 18, height: 18)
// }
// // backButton.frame = CGRect(x: 0, y: 0, width: uiscreen.height * 0.01, height: uiscreen.height * 0.01)
// // backButton.backgroundColor = .red
// backButton.imageView!.contentMode = .scaleAspectFit
// //backButton.setBackgroundImage(UIImage(named:Assets.Navigation.backButton), for: UIControlState())
// // backButton.setImage(UIImage(named: icon), for: .normal)
// backButton.setBackgroundImage(UIImage(named: icon), 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
if (icon == "ic_close_2") {
let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
NSLayoutConstraint.activate([heightContraints,widthContraints])
} else {
let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
NSLayoutConstraint.activate([heightContraints,widthContraints])
}
// backButton.translatesAutoresizingMaskIntoConstraints = false
// // Add width, height constraints
// if (icon == "ic_close_2") {
// let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
// let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
// NSLayoutConstraint.activate([heightContraints,widthContraints])
// } else {
// let widthContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
// let heightContraints = NSLayoutConstraint(item: backButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: 18)
// NSLayoutConstraint.activate([heightContraints,widthContraints])
// }
let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton)
NSLayoutConstraint.activate([(leftBarButtonItem.customView!.widthAnchor.constraint(equalToConstant: 18)),(leftBarButtonItem.customView!.heightAnchor.constraint(equalToConstant: 18))])
self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false)
// let leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: backButton)
// NSLayoutConstraint.activate([(leftBarButtonItem.customView!.widthAnchor.constraint(equalToConstant: 18)),(leftBarButtonItem.customView!.heightAnchor.constraint(equalToConstant: 18))])
// self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: false)
self.navigationItem.setHidesBackButton(true, animated:false)
//your custom view for back image with custom size
let view = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
let imageView = UIImageView(frame: CGRect(x: 10, y: 10, width: 18, height: 18))
if let imgBackArrow = UIImage(named: icon, in: Bundle(for: MyEmptyClass.self), compatibleWith: nil) {
imageView.image = imgBackArrow
}
view.addSubview(imageView)
let backTap = UITapGestureRecognizer(target: self, action: #selector(moveToBack(_:)))
view.addGestureRecognizer(backTap)
let leftBarButtonItem = UIBarButtonItem(customView: view )
self.navigationItem.leftBarButtonItem = leftBarButtonItem
self.navigationItem.title = ""
// Add backgroundColor
......