-
Notifications
You must be signed in to change notification settings - Fork 224
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
Implementation of Cardpart progress bar view #169
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
463 changes: 463 additions & 0 deletions
463
CardParts/src/Classes/Card Parts/CardPartProgressBarView.swift
Large diffs are not rendered by default.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
CardParts/src/Classes/Card Parts/CardPartTriangleView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// CardPartTriangleView.swift | ||
// CardParts | ||
// | ||
// Created by Venkatnarayansetty, Badarinath on 9/19/19. | ||
// | ||
|
||
import Foundation | ||
|
||
class CardPartTriangleView: UIView { | ||
var fillColor: UIColor = UIColor.white | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
} | ||
|
||
override func draw(_ rect: CGRect) { | ||
|
||
let layerHeight = layer.frame.height | ||
|
||
let layerWidth = layer.frame.width | ||
|
||
let bezierPath = UIBezierPath() | ||
|
||
bezierPath.move(to: CGPoint(x: 0, y: 0)) | ||
bezierPath.addLine(to: CGPoint(x: layerWidth, y: 0)) | ||
bezierPath.addLine(to: CGPoint(x: layerWidth / 2, y: layerHeight)) | ||
bezierPath.addLine(to: CGPoint(x: 0, y: 0)) | ||
bezierPath.close() | ||
|
||
fillColor.setFill() | ||
bezierPath.fill() | ||
|
||
let shapeLayer = CAShapeLayer() | ||
shapeLayer.path = bezierPath.cgPath | ||
layer.mask = shapeLayer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Example/CardParts/CardPartProgressBarViewCardController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// CardPartProgressBarViewCardController.swift | ||
// CardParts_Example | ||
// | ||
// Created by Venkatnarayansetty, Badarinath on 9/19/19. | ||
// Copyright © 2019 CocoaPods. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CardParts | ||
import RxCocoa | ||
import RxSwift | ||
|
||
class CardPartProgressBarViewCardController: CardPartsViewController { | ||
|
||
var viewModel = ReactiveCardPartProgressBarViewModel() | ||
|
||
let barColors: [UIColor] = [UIColor.red, | ||
UIColor.green, | ||
UIColor.yellow, | ||
UIColor.purple, | ||
UIColor.blue] | ||
|
||
let barValues: [Double] = [300, 600, 650, 700, 750, 850] | ||
|
||
override func viewDidLoad() { | ||
let progressBarView = CardPartProgressBarView(barValues: barValues, barColors: barColors, marker: nil, markerLabelTitle: "", currentValue: Double(600), showShowBarValues: false) | ||
progressBarView.barCornerRadius = 4.0 | ||
|
||
viewModel.currentValue.asObservable().bind(to: progressBarView.rx.currentValue).disposed(by: bag) | ||
|
||
setupCardParts([progressBarView]) | ||
|
||
invalidateLayout(onChanges: [viewModel.currentValue]) | ||
} | ||
} | ||
|
||
|
||
class ReactiveCardPartProgressBarViewModel { | ||
|
||
var currentValue = BehaviorRelay(value: Double(100)) | ||
|
||
init() { | ||
randomise() | ||
} | ||
|
||
func randomise() { | ||
Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(self.random), userInfo: nil, repeats: true) | ||
} | ||
|
||
@objc func random() { | ||
switch arc4random() % 3 { | ||
case 0: | ||
currentValue.accept(200) | ||
case 1: | ||
currentValue.accept(400) | ||
case 2: | ||
currentValue.accept(600) | ||
|
||
default: | ||
return | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More places that I want to remove and make more generic. Should we make it not
turboGenericLightFontWithSize
but insteadlightFontWithSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we should make it to
lightFontWithSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do it as part of next PR's ?