Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created March 29, 2019 20:09
Show Gist options
  • Select an option

  • Save FabiolaRamirez/0e68bfe5328246446ff5c273718230d7 to your computer and use it in GitHub Desktop.

Select an option

Save FabiolaRamirez/0e68bfe5328246446ff5c273718230d7 to your computer and use it in GitHub Desktop.
//
// ScoreIncreaseSimulationView.swift
// finance
//
// Created by Fabiola Ramirez on 3/27/19.
// Copyright © 2019 creditsesame. All rights reserved.
//
import UIKit
class ScoreIncreaseSimulationView: UIView {
var view: UIView!
var potentialIncreaseImage: UIImageView!
var potentialDecreaseImage: UIImageView!
var potentialIncreaseNumLabel: UILabel!
var potentialDecreaseNumLabel: UILabel!
var potentialIncreaseLabel: UILabel!
var potentialDecreaseLabel: UILabel!
var expandButton: UIButton!
var carrotView: UIImageView!
var stackView: UIStackView!
var expanded = false
override init(frame: CGRect) {
super.init(frame: frame)
setUp()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUp()
}
func setUp() {
backgroundColor = UIColor.clear
view = UIView.loadNib("ScoreIncreaseSimulationView", owner: self)
view.frame = frame
addSubview(view)
view.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
potentialIncreaseImage = view.imageViewWithTag(10)
potentialIncreaseNumLabel = view.labelWithTag(11)
potentialIncreaseLabel = view.labelWithTag(12)
potentialDecreaseImage = view.imageViewWithTag(13)
potentialDecreaseNumLabel = view.labelWithTag(14)
potentialDecreaseLabel = view.labelWithTag(15)
potentialIncreaseImage.image = UIImage(named: "arc")
potentialDecreaseImage.image = UIImage(named: "arc")
expandButton = view.buttonWithTag(16)
carrotView = view.imageViewWithTag(17)
stackView = view.viewWithTag(18) as? UIStackView
expandButton.addTarget(self, action: #selector(pressButton), for: .touchUpInside)
expandButton.titleLabel?.font = UIFont.lato(16)
expandButton.setTitleColor(UIColor.creditSesameGrayTextColor, for: .normal)
}
func configureCCScoreIncreaseSim(potentialIncreseNumber: Int, potentialDecreaseNumber: Int, isExpandedCell: Bool, currentCreditUsageGrade: Grade, goalCreditUsageGrade: Grade, currentCreditAgeGrade: Grade, goalCreditAgeGrade: Grade, currentCreditInquiryGrade: Grade, goalCreditInquiryGrade: Grade, percentageScoreUsage: Int, percentageScoreAge: Int, percentageScoreInquiry: Int, currentPotentialCreditUsageValue: Float, limitPotentialCreditUsageValue: Float, potentialCreditAverageAgeValue: Float, potentialTotalCreditInquiriesValue: Float) {
let potentialIncreaseNumber = NSMutableAttributedString(string: "+\(potentialIncreseNumber)", attributes: [NSAttributedString.Key.font : UIFont.latoBold(20), NSAttributedString.Key.foregroundColor : UIColor.creditSesameGreen])
let tooltipAttachment = NSTextAttachment()
tooltipAttachment.image = UIImage(named: "tooltip_icon")
let imageString = NSAttributedString(attachment: tooltipAttachment)
potentialIncreaseNumber.append(imageString)
potentialIncreaseNumLabel?.attributedText = potentialIncreaseNumber
let potentialIncreaseDescription = NSMutableAttributedString(string: "Potential increase if you're approved ", attributes: [NSAttributedString.Key.font : UIFont.lato(12), NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor])
let tooltipAttachment2 = NSTextAttachment()
tooltipAttachment2.image = UIImage(named: "tooltip_icon")
let imageString2 = NSAttributedString(attachment: tooltipAttachment2)
potentialIncreaseDescription.append(imageString2)
potentialIncreaseLabel?.attributedText = potentialIncreaseDescription
let potentialDecreaseNumber = NSMutableAttributedString(string: "+\(potentialDecreaseNumber)", attributes: [NSAttributedString.Key.font : UIFont.latoBold(20), NSAttributedString.Key.foregroundColor : UIColor.creditSesameGreen])
let tooltipAttachment3 = NSTextAttachment()
tooltipAttachment3.image = UIImage(named: "tooltip_icon")
let imageString3 = NSAttributedString(attachment: tooltipAttachment3)
potentialDecreaseNumber.append(imageString3)
potentialDecreaseNumLabel?.attributedText = potentialDecreaseNumber
let potentialDecreaseDescription = NSMutableAttributedString(string: "Potential decrease if you're declined", attributes: [NSAttributedString.Key.font : UIFont.lato(12), NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor])
let tooltipAttachment4 = NSTextAttachment()
tooltipAttachment4.image = UIImage(named: "tooltip_icon")
let imageString4 = NSAttributedString(attachment: tooltipAttachment4)
potentialDecreaseDescription.append(imageString4)
potentialDecreaseLabel?.attributedText = potentialDecreaseDescription
stackView.isHidden = !isExpandedCell
expandButton.setTitle(NSLocalizedString("Hide score factor changes", comment: "Hide score factor changes"), for: .normal)
let carrotImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
carrotImageView.isUserInteractionEnabled = false
carrotImageView.contentMode = .scaleAspectFit
carrotImageView.image = UIImage(named: "caret_down_icon")
carrotView.isAccessibilityElement = false
for v in carrotView.subviews {
v.removeFromSuperview()
}
carrotView.isHidden = false
carrotView.addSubview(carrotImageView)
if isExpandedCell {
carrotImageView.transform = CGAffineTransform(rotationAngle: .pi)
}
for v in stackView.arrangedSubviews {
stackView.removeArrangedSubview(v)
v.removeFromSuperview()
}
for i in 0..<3 {
let scoreIncreaseView = UIView.loadNib("ScoreIncreaseGrade")
let titleLabel = scoreIncreaseView.labelWithTag(10)!
let currentGradeImage = scoreIncreaseView.imageViewWithTag(11)!
let goalGradeImage = scoreIncreaseView.imageViewWithTag(12)!
let subTitleLabel = scoreIncreaseView.labelWithTag(13)!
let percentageLabel = scoreIncreaseView.labelWithTag(14)!
let potentialCreditLabel = scoreIncreaseView.labelWithTag(15)!
let bottonLabel = scoreIncreaseView.labelWithTag(16)!
let arrowRightImage = scoreIncreaseView.imageViewWithTag(30)!
titleLabel.font = UIFont.latoSemiBold(16)
titleLabel.textColor = UIColor.creditSesameLightGrayTextColor
subTitleLabel.font = UIFont.lato(16)
subTitleLabel.textColor = UIColor.creditSesameGrayTextColor
percentageLabel.font = UIFont.latoSemiBold(12)
percentageLabel.textColor = UIColor.creditSesameLightGrayTextColor
potentialCreditLabel.font = UIFont.latoSemiBold(12)
potentialCreditLabel.textColor = UIColor.creditSesameLightGrayTextColor
arrowRightImage.image = UIImage(named: "arrow_right")
switch i {
case 0:
titleLabel.text = NSLocalizedString("IF YOU'RE APPROVED", comment: "IF YOU'RE APPROVED")
subTitleLabel.text = NSLocalizedString("Potential Credit Usage Grade", comment: "Potential Credit Usage Grade")
percentageLabel.text = "(\(percentageScoreUsage)% of your score)"
potentialCreditLabel.text = NSLocalizedString("Potential new credit usage:", comment: "Potential new credit usage")
let bottonText = NSMutableAttributedString(string: "$\(currentPotentialCreditUsageValue) ", attributes:
[NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor,
NSAttributedString.Key.font : UIFont.latoBold(14)])
let tooltipAttachment = NSTextAttachment()
tooltipAttachment.image = UIImage(named: "tooltip_icon")
let imageString = NSAttributedString(attachment: tooltipAttachment)
bottonText.append(imageString)
bottonText.append(NSAttributedString(string: " out of ", attributes:
[NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor,
NSAttributedString.Key.font : UIFont.lato(14)]))
bottonText.append(NSAttributedString(string: "$\(limitPotentialCreditUsageValue) ", attributes:
[NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor,
NSAttributedString.Key.font : UIFont.latoBold(14)]))
let tooltipAttachment2 = NSTextAttachment()
tooltipAttachment2.image = UIImage(named: "tooltip_icon")
let imageString2 = NSAttributedString(attachment: tooltipAttachment2)
bottonText.append(imageString2)
bottonLabel.attributedText = bottonText
switch currentCreditUsageGrade {
case .A:
currentGradeImage.image = UIImage(named: "grade_A")
case .B :
currentGradeImage.image = UIImage(named: "grade_B")
case .C:
currentGradeImage.image = UIImage(named: "grade_C")
case .D:
currentGradeImage.image = UIImage(named: "grade_D")
case .F:
currentGradeImage.image = UIImage(named: "grade_F")
}
switch goalCreditUsageGrade {
case .A:
goalGradeImage.image = UIImage(named: "grade_A")
case .B :
goalGradeImage.image = UIImage(named: "grade_B")
case .C:
goalGradeImage.image = UIImage(named: "grade_C")
case .D:
goalGradeImage.image = UIImage(named: "grade_D")
case .F:
goalGradeImage.image = UIImage(named: "grade_F")
}
case 1:
titleLabel.text = ""
subTitleLabel.text = NSLocalizedString("Potential Credit Age Grade", comment: "Potential Credit Age Grade")
percentageLabel.text = "(\(percentageScoreAge)% of your score)"
potentialCreditLabel.text = NSLocalizedString("Potential new credit average age:", comment: "Potential new credit average age")
let bottonText = NSMutableAttributedString(string: "\(potentialCreditAverageAgeValue) years ", attributes:
[NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor,
NSAttributedString.Key.font : UIFont.latoBold(14)])
let tooltipAttachment = NSTextAttachment()
tooltipAttachment.image = UIImage(named: "tooltip_icon")
let imageString = NSAttributedString(attachment: tooltipAttachment)
bottonText.append(imageString)
bottonLabel.attributedText = bottonText
switch currentCreditAgeGrade {
case .A:
currentGradeImage.image = UIImage(named: "grade_A")
case .B :
currentGradeImage.image = UIImage(named: "grade_B")
case .C:
currentGradeImage.image = UIImage(named: "grade_C")
case .D:
currentGradeImage.image = UIImage(named: "grade_D")
case .F:
currentGradeImage.image = UIImage(named: "grade_F")
}
switch goalCreditAgeGrade {
case .A:
goalGradeImage.image = UIImage(named: "grade_A")
case .B :
goalGradeImage.image = UIImage(named: "grade_B")
case .C:
goalGradeImage.image = UIImage(named: "grade_C")
case .D:
goalGradeImage.image = UIImage(named: "grade_D")
case .F:
goalGradeImage.image = UIImage(named: "grade_F")
}
case 2:
titleLabel.text = NSLocalizedString("IF YOU'RE APPROVED OR DENIED", comment: "IF YOU'RE APPROVED OR DENIED")
subTitleLabel.text = NSLocalizedString("Potential Credit Inquiry Grade", comment: "Potential Credit Inquiry Grade")
percentageLabel.text = "(\(percentageScoreInquiry)% of your score)"
potentialCreditLabel.text = NSLocalizedString("Potential total credit inquiries:", comment: "Potential total credit inquiries")
let bottonText = NSMutableAttributedString(string: "\(potentialTotalCreditInquiriesValue) ", attributes:
[NSAttributedString.Key.foregroundColor : UIColor.creditSesameGrayTextColor,
NSAttributedString.Key.font : UIFont.latoBold(14)])
let tooltipAttachment = NSTextAttachment()
tooltipAttachment.image = UIImage(named: "tooltip_icon")
let imageString = NSAttributedString(attachment: tooltipAttachment)
bottonText.append(imageString)
bottonLabel.attributedText = bottonText
switch currentCreditInquiryGrade {
case .A:
currentGradeImage.image = UIImage(named: "grade_A")
case .B :
currentGradeImage.image = UIImage(named: "grade_B")
case .C:
currentGradeImage.image = UIImage(named: "grade_C")
case .D:
currentGradeImage.image = UIImage(named: "grade_D")
case .F:
currentGradeImage.image = UIImage(named: "grade_F")
}
switch goalCreditInquiryGrade {
case .A:
goalGradeImage.image = UIImage(named: "grade_A")
case .B :
goalGradeImage.image = UIImage(named: "grade_B")
case .C:
goalGradeImage.image = UIImage(named: "grade_C")
case .D:
goalGradeImage.image = UIImage(named: "grade_D")
case .F:
goalGradeImage.image = UIImage(named: "grade_F")
}
default:
break
}
stackView.addArrangedSubview(scoreIncreaseView)
}
stackView.translatesAutoresizingMaskIntoConstraints = false
expandButton.addBottomSeparator()
//expandView.addBottomSeparator()*/
}
@objc func pressButton(sender:UIButton!) {
print("Button Clicked")
stackView.isHidden = !expanded
let carrotImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
carrotImageView.isUserInteractionEnabled = false
carrotImageView.contentMode = .scaleAspectFit
carrotImageView.image = UIImage(named: "caret_down_icon")
carrotView.isAccessibilityElement = false
for v in carrotView.subviews {
v.removeFromSuperview()
}
carrotView.isHidden = false
carrotView.addSubview(carrotImageView)
if expanded {
carrotImageView.transform = CGAffineTransform(rotationAngle: .pi)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment