added methods for showing button cell bounds
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
3e8461aef6
commit
29a36ee7d4
@ -169,6 +169,11 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
|
|||||||
cell.subviews.forEach { $0.removeFromSuperview() }
|
cell.subviews.forEach { $0.removeFromSuperview() }
|
||||||
cell.addSubview(button)
|
cell.addSubview(button)
|
||||||
button.pinToSuperView()
|
button.pinToSuperView()
|
||||||
|
if hasDebugBorder {
|
||||||
|
cell.addDebugBorder()
|
||||||
|
} else {
|
||||||
|
cell.removeDebugBorder()
|
||||||
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,5 +193,4 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
|
|||||||
buttons[indexPath.row]
|
buttons[indexPath.row]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,9 +118,9 @@ extension UIView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extension UIView {
|
extension UIView {
|
||||||
private func removeDebugBorder() {
|
|
||||||
|
internal func removeDebugBorder() {
|
||||||
layer.sublayers?.forEach({ layer in
|
layer.sublayers?.forEach({ layer in
|
||||||
if layer.name?.hasPrefix("debug") ?? false {
|
if layer.name?.hasPrefix("debug") ?? false {
|
||||||
layer.removeFromSuperlayer()
|
layer.removeFromSuperlayer()
|
||||||
@ -128,34 +128,52 @@ extension UIView {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) {
|
internal func addDebugBorder(color: UIColor = .red) {
|
||||||
|
//ensure you remove existing
|
||||||
removeDebugBorder()
|
removeDebugBorder()
|
||||||
|
|
||||||
|
//add bounds border
|
||||||
|
let borderLayer = CALayer()
|
||||||
|
borderLayer.name = "debugAreaLayer"
|
||||||
|
borderLayer.frame = bounds
|
||||||
|
borderLayer.bounds = bounds
|
||||||
|
borderLayer.borderWidth = VDSFormControls.widthBorder
|
||||||
|
borderLayer.borderColor = color.cgColor
|
||||||
|
layer.addSublayer(borderLayer)
|
||||||
|
|
||||||
|
//add touchborder if applicable
|
||||||
|
if type(of: self) is AppleGuidlinesTouchable.Type {
|
||||||
|
let faultToleranceX: CGFloat = max((45 - bounds.size.width) / 2.0, 0)
|
||||||
|
let faultToleranceY: CGFloat = max((45 - bounds.size.height) / 2.0, 0)
|
||||||
|
|
||||||
|
let touchableAreaPath = UIBezierPath(rect: bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY))
|
||||||
|
let touchLayer = CAShapeLayer()
|
||||||
|
touchLayer.path = touchableAreaPath.cgPath
|
||||||
|
touchLayer.strokeColor = color.cgColor
|
||||||
|
touchLayer.fillColor = UIColor.clear.cgColor
|
||||||
|
touchLayer.lineWidth = VDSFormControls.widthBorder
|
||||||
|
touchLayer.opacity = 1.0
|
||||||
|
touchLayer.name = "debugTouchableAreaLayer"
|
||||||
|
touchLayer.zPosition = 100
|
||||||
|
touchLayer.frame = bounds
|
||||||
|
touchLayer.bounds = bounds
|
||||||
|
layer.addSublayer(touchLayer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var hasDebugBorder: Bool {
|
||||||
|
guard let layers = layer.sublayers else { return false }
|
||||||
|
return layers.compactMap{$0.name}.filter{$0.hasPrefix("debug")}.count > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
public func debugBorder(show shouldShow: Bool = true, color: UIColor = .red) {
|
||||||
if shouldShow {
|
if shouldShow {
|
||||||
let borderLayer = CALayer()
|
addDebugBorder(color: color)
|
||||||
borderLayer.name = "debugAreaLayer"
|
} else {
|
||||||
borderLayer.frame = bounds
|
removeDebugBorder()
|
||||||
borderLayer.bounds = bounds
|
}
|
||||||
borderLayer.borderWidth = VDSFormControls.widthBorder
|
if let view = self as? Handlerable {
|
||||||
borderLayer.borderColor = color.cgColor
|
view.updateView()
|
||||||
layer.addSublayer(borderLayer)
|
|
||||||
|
|
||||||
if type(of: self) is AppleGuidlinesTouchable.Type {
|
|
||||||
let faultToleranceX: CGFloat = max((45 - bounds.size.width) / 2.0, 0)
|
|
||||||
let faultToleranceY: CGFloat = max((45 - bounds.size.height) / 2.0, 0)
|
|
||||||
|
|
||||||
let touchableAreaPath = UIBezierPath(rect: bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY))
|
|
||||||
let touchLayer = CAShapeLayer()
|
|
||||||
touchLayer.path = touchableAreaPath.cgPath
|
|
||||||
touchLayer.strokeColor = color.cgColor
|
|
||||||
touchLayer.fillColor = UIColor.clear.cgColor
|
|
||||||
touchLayer.lineWidth = VDSFormControls.widthBorder
|
|
||||||
touchLayer.opacity = 1.0
|
|
||||||
touchLayer.name = "debugTouchableAreaLayer"
|
|
||||||
touchLayer.zPosition = 100
|
|
||||||
touchLayer.frame = bounds
|
|
||||||
touchLayer.bounds = bounds
|
|
||||||
layer.addSublayer(touchLayer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user