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.
		
		
		
		
		
			
		
			
	
	
		
			68 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			68 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
| 
											5 years ago
										 | import UIKit | ||
| 
											6 years ago
										 | 
 | ||
| 
											5 years ago
										 | public final class Separator : UIView { | ||
| 
											6 years ago
										 |     private let title: String | ||
|  |      | ||
|  |     // MARK: Components | ||
|  |     private lazy var titleLabel: UILabel = { | ||
|  |         let result = UILabel() | ||
|  |         result.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity) | ||
|  |         result.font = .systemFont(ofSize: Values.smallFontSize) | ||
|  |         result.textAlignment = .center | ||
|  |         return result | ||
|  |     }() | ||
|  |      | ||
|  |     private lazy var lineLayer: CAShapeLayer = { | ||
|  |         let result = CAShapeLayer() | ||
|  |         result.lineWidth = Values.separatorThickness | ||
|  |         result.strokeColor = Colors.separator.cgColor | ||
|  |         result.fillColor = UIColor.clear.cgColor | ||
|  |         return result | ||
|  |     }() | ||
|  |      | ||
|  |     // MARK: Initialization | ||
| 
											5 years ago
										 |     public init(title: String) { | ||
| 
											6 years ago
										 |         self.title = title | ||
|  |         super.init(frame: CGRect.zero) | ||
|  |         setUpViewHierarchy() | ||
|  |     } | ||
|  |      | ||
| 
											5 years ago
										 |     public override init(frame: CGRect) { | ||
| 
											6 years ago
										 |         preconditionFailure("Use init(title:) instead.") | ||
|  |     } | ||
|  |      | ||
| 
											5 years ago
										 |     public required init?(coder: NSCoder) { | ||
| 
											6 years ago
										 |         preconditionFailure("Use init(title:) instead.") | ||
|  |     } | ||
|  |      | ||
|  |     private func setUpViewHierarchy() { | ||
|  |         titleLabel.text = title | ||
|  |         addSubview(titleLabel) | ||
|  |         titleLabel.center(.horizontal, in: self) | ||
|  |         titleLabel.center(.vertical, in: self) | ||
|  |         layer.insertSublayer(lineLayer, at: 0) | ||
| 
											6 years ago
										 |         set(.height, to: Values.separatorLabelHeight) | ||
| 
											6 years ago
										 |     } | ||
|  |      | ||
|  |     // MARK: Updating | ||
| 
											5 years ago
										 |     public override func layoutSubviews() { | ||
| 
											6 years ago
										 |         super.layoutSubviews() | ||
|  |         updateLineLayer() | ||
|  |     } | ||
|  |      | ||
|  |     private func updateLineLayer() { | ||
| 
											5 years ago
										 |         let w = bounds.width | ||
|  |         let h = bounds.height | ||
| 
											6 years ago
										 |         let path = UIBezierPath() | ||
|  |         path.move(to: CGPoint(x: 0, y: h / 2)) | ||
|  |         let titleLabelFrame = titleLabel.frame.insetBy(dx: -10, dy: -6) | ||
|  |         path.addLine(to: CGPoint(x: titleLabelFrame.origin.x, y: h / 2)) | ||
| 
											6 years ago
										 |         let oval = UIBezierPath(roundedRect: titleLabelFrame, cornerRadius: Values.separatorLabelHeight / 2) | ||
| 
											6 years ago
										 |         path.append(oval) | ||
|  |         path.move(to: CGPoint(x: titleLabelFrame.origin.x + titleLabelFrame.width, y: h / 2)) | ||
|  |         path.addLine(to: CGPoint(x: w, y: h / 2)) | ||
|  |         path.close() | ||
|  |         lineLayer.path = path.cgPath | ||
|  |     } | ||
|  | } |