removed lineHeight/verticalPadding from the sizes
added new bezierPathBorder Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
bc8df2d45f
commit
c57c597427
@ -87,47 +87,38 @@ open class BadgeIndicator: View {
|
|||||||
var font: Font = .edsRegular
|
var font: Font = .edsRegular
|
||||||
var pointSize: CGFloat = VDSTypography.fontSizeBody12
|
var pointSize: CGFloat = VDSTypography.fontSizeBody12
|
||||||
var letterSpacing: CGFloat = 0.0
|
var letterSpacing: CGFloat = 0.0
|
||||||
var lineHeight: CGFloat = 0.0
|
|
||||||
var edgeInsets: UIEdgeInsets = .zero
|
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case .xxlarge:
|
case .xxlarge:
|
||||||
pointSize = VDSTypography.fontSizeTitle24
|
pointSize = VDSTypography.fontSizeTitle24
|
||||||
lineHeight = VDSTypography.lineHeightTitle24
|
|
||||||
|
|
||||||
case .xlarge:
|
case .xlarge:
|
||||||
pointSize = VDSTypography.fontSizeTitle20
|
pointSize = VDSTypography.fontSizeTitle20
|
||||||
lineHeight = VDSTypography.lineHeightTitle20
|
|
||||||
|
|
||||||
case .large:
|
case .large:
|
||||||
pointSize = VDSTypography.fontSizeBody16
|
pointSize = VDSTypography.fontSizeBody16
|
||||||
letterSpacing = VDSTypography.letterSpacingWide
|
letterSpacing = VDSTypography.letterSpacingWide
|
||||||
lineHeight = VDSTypography.lineHeightBody16
|
|
||||||
|
|
||||||
case .medium:
|
case .medium:
|
||||||
pointSize = VDSTypography.fontSizeBody14
|
pointSize = VDSTypography.fontSizeBody14
|
||||||
letterSpacing = VDSTypography.letterSpacingWide
|
letterSpacing = VDSTypography.letterSpacingWide
|
||||||
lineHeight = 14.0
|
|
||||||
|
|
||||||
case .small:
|
case .small:
|
||||||
font = .etxRegular
|
font = .etxRegular
|
||||||
pointSize = VDSTypography.fontSizeBody12
|
pointSize = VDSTypography.fontSizeBody12
|
||||||
lineHeight = 12.0
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextStyle(rawValue: "\(self.rawValue)BadgeIndicator",
|
return TextStyle(rawValue: "\(self.rawValue)BadgeIndicator",
|
||||||
fontFace: font,
|
fontFace: font,
|
||||||
pointSize: pointSize,
|
pointSize: pointSize,
|
||||||
lineHeight: lineHeight,
|
lineHeight: 0,
|
||||||
letterSpacing: letterSpacing,
|
letterSpacing: letterSpacing)
|
||||||
edgeInsets: edgeInsets)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//EdgeInsets for the label.
|
//EdgeInsets for the label.
|
||||||
public var edgeInset: UIEdgeInsets {
|
public var edgeInset: UIEdgeInsets {
|
||||||
var horizontalPadding: CGFloat = 0.0
|
var horizontalPadding: CGFloat = 0.0
|
||||||
let verticalPadding: CGFloat = 2.0
|
let verticalPadding: CGFloat = 0.0
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
case .xxlarge:
|
case .xxlarge:
|
||||||
@ -376,10 +367,9 @@ open class BadgeIndicator: View {
|
|||||||
|
|
||||||
//border
|
//border
|
||||||
if hideBorder {
|
if hideBorder {
|
||||||
layer.borderWidth = 0
|
removeBezierPathBorder()
|
||||||
} else {
|
} else {
|
||||||
layer.borderWidth = borderWidth
|
bezierPathBorder(borderColorConfiguration.getColor(surface), width: borderWidth)
|
||||||
layer.borderColor = borderColorConfiguration.getColor(surface).cgColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//dot
|
//dot
|
||||||
@ -464,5 +454,4 @@ open class BadgeIndicator: View {
|
|||||||
let maxNumber = Int(pow(10.0, Double(maxDigits))) - 1
|
let maxNumber = Int(pow(10.0, Double(maxDigits))) - 1
|
||||||
return min(number, maxNumber)
|
return min(number, maxNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -148,3 +148,44 @@ extension UIView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension UIView {
|
||||||
|
|
||||||
|
fileprivate var bezierPathIdentifier: String { return "bezierPathBorderLayer" }
|
||||||
|
|
||||||
|
fileprivate var bezierPathBorder: CAShapeLayer? {
|
||||||
|
return (self.layer.sublayers?.filter({ (layer) -> Bool in
|
||||||
|
return layer.name == self.bezierPathIdentifier && (layer as? CAShapeLayer) != nil
|
||||||
|
}) as? [CAShapeLayer])?.first
|
||||||
|
}
|
||||||
|
|
||||||
|
public func bezierPathBorder(_ color: UIColor = .white, width: CGFloat = 1) {
|
||||||
|
|
||||||
|
var border = self.bezierPathBorder
|
||||||
|
let path = UIBezierPath(roundedRect: self.bounds, cornerRadius:self.layer.cornerRadius)
|
||||||
|
let mask = CAShapeLayer()
|
||||||
|
mask.path = path.cgPath
|
||||||
|
self.layer.mask = mask
|
||||||
|
|
||||||
|
if (border == nil) {
|
||||||
|
border = CAShapeLayer()
|
||||||
|
border!.name = self.bezierPathIdentifier
|
||||||
|
self.layer.addSublayer(border!)
|
||||||
|
}
|
||||||
|
|
||||||
|
border!.frame = self.bounds
|
||||||
|
let pathUsingCorrectInsetIfAny =
|
||||||
|
UIBezierPath(roundedRect: border!.bounds, cornerRadius:self.layer.cornerRadius)
|
||||||
|
|
||||||
|
border!.path = pathUsingCorrectInsetIfAny.cgPath
|
||||||
|
border!.fillColor = UIColor.clear.cgColor
|
||||||
|
border!.strokeColor = color.cgColor
|
||||||
|
border!.lineWidth = width * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
public func removeBezierPathBorder() {
|
||||||
|
self.layer.mask = nil
|
||||||
|
self.bezierPathBorder?.removeFromSuperlayer()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user