From 153012e1860fa9c6d30cd5b12508993e481f5896 Mon Sep 17 00:00:00 2001 From: RATTANDEEP SINGH Date: Tue, 29 Sep 2020 00:14:09 +0530 Subject: [PATCH] Custom border radius support for bar view (#259) Co-authored-by: RATTANDEEP SINGH --- .../src/Classes/Card Parts/CardPartBarView.swift | 13 +++++++++++-- CardParts/src/Classes/CardPartsTheme.swift | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CardParts/src/Classes/Card Parts/CardPartBarView.swift b/CardParts/src/Classes/Card Parts/CardPartBarView.swift index 0e5f881d..b54b966e 100644 --- a/CardParts/src/Classes/Card Parts/CardPartBarView.swift +++ b/CardParts/src/Classes/Card Parts/CardPartBarView.swift @@ -12,6 +12,7 @@ import RxCocoa public class CardPartBarView: UIView, CardPartView { public var margins: UIEdgeInsets = CardParts.theme.cardPartMargins + public var cornerRadius: CGFloat? = CardParts.theme.barCornerRadius public var backgroundLayer: CALayer! public var barLayer: CALayer! public var verticalLine: CALayer! @@ -87,13 +88,21 @@ public class CardPartBarView: UIView, CardPartView { barLayer.bounds = bounds barLayer.backgroundColor = barColor.cgColor if CardParts.theme.roundedCorners { - barLayer.cornerRadius = bounds.height / 2 + if let desiredCornerRadius: CGFloat = cornerRadius { + barLayer.cornerRadius = desiredCornerRadius + } else { + barLayer.cornerRadius = bounds.height / 2 + } } let backgroundBounds = CGRect(x: 0, y: 0, width: self.bounds.width , height: desiredHeight) backgroundLayer.bounds = backgroundBounds if CardParts.theme.roundedCorners { - backgroundLayer.cornerRadius = bounds.height / 2 + if let desiredCornerRadius: CGFloat = cornerRadius { + barLayer.cornerRadius = desiredCornerRadius + } else { + barLayer.cornerRadius = bounds.height / 2 + } } if CardParts.theme.showTodayLine { diff --git a/CardParts/src/Classes/CardPartsTheme.swift b/CardParts/src/Classes/CardPartsTheme.swift index 57b832d2..7585bf95 100644 --- a/CardParts/src/Classes/CardPartsTheme.swift +++ b/CardParts/src/Classes/CardPartsTheme.swift @@ -61,6 +61,7 @@ public protocol CardPartsTheme { var todayLineColor: UIColor { get set } var roundedCorners: Bool { get set } var showTodayLine: Bool { get set } + var barCornerRadius: CGFloat? { get set } // CardPartTableView and CardPartCollectionView var tableViewMargins: UIEdgeInsets { get set } @@ -138,7 +139,8 @@ public class CardPartsMintTheme: CardPartsTheme { public var barHeight: CGFloat = 13.5 public var roundedCorners: Bool = false public var showTodayLine: Bool = true - + public var barCornerRadius: CGFloat? = nil + // CardPartTableView public var tableViewMargins: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 14.0, bottom: 0.0, right: 14.0) @@ -213,7 +215,8 @@ public class CardPartsTurboTheme: CardPartsTheme { public var barHeight: CGFloat = 20.0 public var roundedCorners: Bool = true public var showTodayLine: Bool = false - + public var barCornerRadius: CGFloat? = nil + // CardPartTableView public var tableViewMargins: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 28.0, bottom: 0.0, right: 28.0)