@ -7,6 +7,22 @@ public final class Separator: UIView {
// MARK: - C o m p o n e n t s
// MARK: - C o m p o n e n t s
private let leftLine : UIView = {
let result : UIView = UIView ( )
result . themeBackgroundColor = . textSecondary
result . set ( . height , to : Values . separatorThickness )
return result
} ( )
private let roundedLine : UIView = {
let result : UIView = UIView ( )
result . themeBorderColor = . textSecondary
result . layer . borderWidth = Values . separatorThickness
return result
} ( )
private lazy var titleLabel : UILabel = {
private lazy var titleLabel : UILabel = {
let result = UILabel ( )
let result = UILabel ( )
result . font = . systemFont ( ofSize : Values . smallFontSize )
result . font = . systemFont ( ofSize : Values . smallFontSize )
@ -16,11 +32,10 @@ public final class Separator: UIView {
return result
return result
} ( )
} ( )
private lazy var lineLayer : CAShapeLayer = {
private let rightLine : UIView = {
let result = CAShapeLayer ( )
let result : UIView = UIView ( )
result . lineWidth = Values . separatorThickness
result . themeBackgroundColor = . textSecondary
result . themeStrokeColor = . textSecondary
result . set ( . height , to : Values . separatorThickness )
result . themeFillColor = . clear
return result
return result
} ( )
} ( )
@ -47,40 +62,35 @@ public final class Separator: UIView {
private func setUpViewHierarchy ( title : String ? ) {
private func setUpViewHierarchy ( title : String ? ) {
titleLabel . text = title
titleLabel . text = title
addSubview ( leftLine )
addSubview ( roundedLine )
addSubview ( rightLine )
addSubview ( titleLabel )
addSubview ( titleLabel )
titleLabel . center ( . horizontal , in : self )
titleLabel . center ( . horizontal , in : self )
titleLabel . center ( . vertical , in : self )
titleLabel . center ( . vertical , in : self )
layer . insertSublayer ( lineLayer , at : 0 )
roundedLine . pin ( . top , to : . top , of : self )
roundedLine . pin ( . top , to : . top , of : titleLabel , withInset : - 6 )
set ( . height , to : Separator . height )
roundedLine . pin ( . leading , to : . leading , of : titleLabel , withInset : - 10 )
roundedLine . pin ( . trailing , to : . trailing , of : titleLabel , withInset : 10 )
roundedLine . pin ( . bottom , to : . bottom , of : titleLabel , withInset : 6 )
roundedLine . pin ( . bottom , to : . bottom , of : self )
leftLine . pin ( . leading , to : . leading , of : self )
leftLine . pin ( . trailing , to : . leading , of : roundedLine )
leftLine . center ( . vertical , in : self )
rightLine . pin ( . leading , to : . trailing , of : roundedLine )
rightLine . pin ( . trailing , to : . trailing , of : self )
rightLine . center ( . vertical , in : self )
}
}
// MARK: - U p d a t i n g
public override func layoutSubviews ( ) {
public override func layoutSubviews ( ) {
super . layoutSubviews ( )
super . layoutSubviews ( )
updateLineLayer ( )
roundedLine. layer . cornerRadius = ( roundedLine . bounds . height / 2 )
}
}
private func updateLineLayer ( ) {
// MARK: - U p d a t i n g
let w = bounds . width
let h = bounds . 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 : Separator . height / 2 )
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
}
public func update ( title : String ? ) {
public func update ( title : String ? ) {
titleLabel . text = title
titleLabel . text = title