Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom corner radius support for CardPartBarView #259

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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