mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			62 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			62 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
| 
											7 years ago
										 | // | ||
|  | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
|  | // | ||
|  | 
 | ||
|  | import UIKit | ||
| 
											5 years ago
										 | import SessionUIKit | ||
| 
											7 years ago
										 | 
 | ||
|  | public extension NSObject { | ||
|  | 
 | ||
| 
											6 years ago
										 |     func navigationBarButton(imageName: String, | ||
| 
											7 years ago
										 |                                      selector: Selector) -> UIView { | ||
|  |         let button = OWSButton() | ||
|  |         button.setImage(imageName: imageName) | ||
| 
											5 years ago
										 |         button.tintColor = isLightMode ? UIColor.black : UIColor.white | ||
| 
											7 years ago
										 |         button.addTarget(self, action: selector, for: .touchUpInside) | ||
|  |         return button | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | // MARK: - | ||
|  | 
 | ||
|  | public extension UIViewController { | ||
|  | 
 | ||
| 
											6 years ago
										 |     func updateNavigationBar(navigationBarItems: [UIView]) { | ||
| 
											7 years ago
										 |         guard navigationBarItems.count > 0 else { | ||
|  |             self.navigationItem.rightBarButtonItems = [] | ||
|  |             return | ||
|  |         } | ||
|  | 
 | ||
| 
											7 years ago
										 |         let spacing: CGFloat = 16 | ||
| 
											7 years ago
										 |         let stackView = UIStackView(arrangedSubviews: navigationBarItems) | ||
|  |         stackView.axis = .horizontal | ||
| 
											7 years ago
										 |         stackView.spacing = spacing | ||
| 
											7 years ago
										 |         stackView.alignment = .center | ||
| 
											6 years ago
										 |          | ||
| 
											7 years ago
										 |         // Ensure layout works on older versions of iOS. | ||
|  |         var stackSize = CGSize.zero | ||
|  |         for item in navigationBarItems { | ||
|  |             let itemSize = item.sizeThatFits(.zero) | ||
|  |             stackSize.width += itemSize.width + spacing | ||
|  |             stackSize.height = max(stackSize.height, itemSize.height) | ||
|  |         } | ||
|  |         if navigationBarItems.count > 0 { | ||
|  |             stackSize.width -= spacing | ||
|  |         } | ||
|  |         stackView.frame = CGRect(origin: .zero, size: stackSize) | ||
|  | 
 | ||
| 
											7 years ago
										 |         self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: stackView) | ||
| 
											6 years ago
										 |          | ||
|  |         // Loki: Set navigation bar background color | ||
|  |         let navigationBar = navigationController!.navigationBar | ||
|  |         navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default) | ||
|  |         navigationBar.shadowImage = UIImage() | ||
|  |         navigationBar.isTranslucent = false | ||
| 
											5 years ago
										 |         let color = isLightMode ? UIColor(hex: 0xFCFCFC) : UIColor(hex: 0x161616) | ||
|  |         navigationBar.barTintColor = color | ||
|  |         navigationBar.backgroundColor = color | ||
|  |         let backgroundImage = UIImage(color: color) | ||
| 
											6 years ago
										 |         navigationBar.setBackgroundImage(backgroundImage, for: .default) | ||
| 
											7 years ago
										 |     } | ||
|  | } |