Skip to content

Commit

Permalink
Custom border radius support for bar view (#259)
Browse files Browse the repository at this point in the history
Co-authored-by: RATTANDEEP SINGH <rattandeep_singh@intuit.com>
  • Loading branch information
rattandeep1998 and RATTANDEEP SINGH authored Sep 28, 2020
1 parent 1a2965e commit 153012e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions CardParts/src/Classes/Card Parts/CardPartBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions CardParts/src/Classes/CardPartsTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 153012e

Please sign in to comment.