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.
		
		
		
		
		
			
		
			
	
	
		
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Swift
		
	
| 
											6 years ago
										 | 
 | ||
|  | final class Separator : UIView { | ||
|  |     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 | ||
|  |     init(title: String) { | ||
|  |         self.title = title | ||
|  |         super.init(frame: CGRect.zero) | ||
|  |         setUpViewHierarchy() | ||
|  |     } | ||
|  |      | ||
|  |     override init(frame: CGRect) { | ||
|  |         preconditionFailure("Use init(title:) instead.") | ||
|  |     } | ||
|  |      | ||
|  |     required init?(coder: NSCoder) { | ||
|  |         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) | ||
|  |     } | ||
|  |      | ||
|  |     // MARK: Updating | ||
|  |     override func layoutSubviews() { | ||
|  |         super.layoutSubviews() | ||
|  |         updateLineLayer() | ||
|  |     } | ||
|  |      | ||
|  |     private func updateLineLayer() { | ||
|  |         let w = width() | ||
|  |         let h = height() | ||
|  |         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)) | ||
|  |         let oval = UIBezierPath(roundedRect: titleLabelFrame, cornerRadius: Values.separatorCornerRadius) | ||
|  |         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 | ||
|  |     } | ||
|  | } |