Skip to content

Commit

Permalink
UI Adjustments
Browse files Browse the repository at this point in the history
Initialization from code fixed
Bug Fixes
Readme updated
  • Loading branch information
PaoloCuscela committed Oct 11, 2017
1 parent 09a10f1 commit e4ab6f2
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 174 deletions.
Binary file removed .DS_Store
Binary file not shown.
21 changes: 10 additions & 11 deletions Cards/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import UIKit

protocol CardDelegate {
@objc protocol CardDelegate {

func cardDidTapButton(button: UIButton)
func cardDidTapInside(card: Card)
@objc optional func cardDidTapButton(button: UIButton)
@objc optional func cardDidTapInside(card: Card)
}

@IBDesignable class Card: UIView {
Expand All @@ -25,23 +25,25 @@ protocol CardDelegate {
@IBInspectable var textColor: UIColor = UIColor.white
@IBInspectable var insets: CGFloat = 6
@IBInspectable var cardRadius: CGFloat = 20
@IBInspectable var maxTitleFontSize: CGFloat = 26


//Priv Vars
var backgroundIV = UIImageView()
internal var backgroundIV = UIImageView()

// View Life Cycle
override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}

func initialize() {
self.backgroundColor = UIColor.clear

self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.cardTapped)))

addSubview(backgroundIV)
self.addSubview(backgroundIV)
}


Expand Down Expand Up @@ -73,7 +75,6 @@ protocol CardDelegate {

//Actions
@objc func cardTapped(){
print("card tapped")
UIView.animate(withDuration: 0.2, animations: {
self.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
}) { (true) in
Expand All @@ -82,8 +83,6 @@ protocol CardDelegate {
})
}
}


}


Expand Down
25 changes: 16 additions & 9 deletions Cards/CardArticle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,36 @@ import UIKit

// SB Vars
@IBInspectable var title: String = "The Art of the Impossible"
@IBInspectable var titleSize: CGFloat = 26
@IBInspectable var subtitle: String = "Inside the extraordinary world of Monument Valley 2"
@IBInspectable var subtitleSize: CGFloat = 17
@IBInspectable var category: String = "world premiere"
@IBInspectable var blurEffect: UIBlurEffectStyle = UIBlurEffectStyle.extraLight

// Delegate
var delegate: CardDelegate?

//Priv Vars
var titleLbl = UILabel ()
var subtitleLbl = UILabel()
var categoryLbl = UILabel()
internal var titleLbl = UILabel ()
internal var subtitleLbl = UILabel()
internal var categoryLbl = UILabel()

// View Life Cycle
override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

initialize()
}

override func initialize() {
super.initialize()

backgroundIV.addSubview(titleLbl)
backgroundIV.addSubview(subtitleLbl)
backgroundIV.addSubview(categoryLbl)

}


Expand Down Expand Up @@ -66,18 +73,18 @@ import UIKit
titleLbl.frame = CGRect(x: X(insets), y: Y(1, from: categoryLbl), width: X(80), height: Y(17))
titleLbl.textColor = textColor
titleLbl.text = title
titleLbl.font = UIFont.systemFont(ofSize: self.maxTitleFontSize, weight: .bold)
titleLbl.font = UIFont.systemFont(ofSize: titleSize, weight: .bold)
titleLbl.adjustsFontSizeToFitWidth = true
titleLbl.minimumScaleFactor = 0.1
titleLbl.lineBreakMode = .byClipping
titleLbl.numberOfLines = 2
titleLbl.baselineAdjustment = .none
titleLbl.sizeToFit()

subtitleLbl.frame = CGRect(x: X(insets), y: RevY(insets*(frame.width/frame.height), height: Y(7)), width: X(100-(insets*2)), height: Y(10))
subtitleLbl.frame = CGRect(x: X(insets), y: RevY(insets*(frame.width/frame.height), height: Y(14)), width: X(100-(insets*2)), height: Y(14))
subtitleLbl.text = subtitle
subtitleLbl.textColor = textColor
subtitleLbl.font = UIFont.systemFont(ofSize: 100, weight: .medium)
subtitleLbl.font = UIFont.systemFont(ofSize: subtitleSize, weight: .medium)
subtitleLbl.shadowColor = UIColor.black
subtitleLbl.shadowOffset = CGSize.zero
subtitleLbl.adjustsFontSizeToFitWidth = true
Expand All @@ -90,7 +97,7 @@ import UIKit

override func cardTapped() {
super.cardTapped()
delegate?.cardDidTapInside(card: self)
delegate?.cardDidTapInside?(card: self)
}

}
Expand Down
71 changes: 39 additions & 32 deletions Cards/CardGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,43 @@ import UIKit
@IBDesignable class CardGroup: Card {

// SB Vars
@IBInspectable var title: String = "from the editors"
@IBInspectable var subtitle: String = "Welcome to XI Cards !"
@IBInspectable var title: String = "Welcome to XI Cards !"
@IBInspectable var titleSize: CGFloat = 26
@IBInspectable var subtitle: String = "from the editors"
@IBInspectable var subtitleSize: CGFloat = 26
@IBInspectable var blurEffect: UIBlurEffectStyle = UIBlurEffectStyle.extraLight

// Delegate
var delegate: CardDelegate?

//Priv Vars
var titleLbl = UILabel ()
var subtitleLbl = UILabel()
var blurV = UIVisualEffectView()
var vibrancyV = UIVisualEffectView()
internal var subtitleLbl = UILabel ()
internal var titleLbl = UILabel()
internal var blurV = UIVisualEffectView()
internal var vibrancyV = UIVisualEffectView()


// View Life Cycle
override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}

override func initialize() {
super.initialize()

vibrancyV = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: blurEffect)))


backgroundIV.addSubview(blurV)
blurV.contentView.addSubview(subtitleLbl)
blurV.contentView.addSubview(titleLbl)
blurV.contentView.addSubview(vibrancyV)
vibrancyV.contentView.addSubview(titleLbl)

vibrancyV.contentView.addSubview(subtitleLbl)
}


override func draw(_ rect: CGRect) {

// Helpers func
Expand All @@ -54,38 +61,38 @@ import UIKit
//Draw
super.draw(rect)

subtitleLbl.frame = CGRect(x: X(insets), y: X(insets), width: X(100-(insets*2)), height: Y(5))
subtitleLbl.text = subtitle.uppercased()
subtitleLbl.textColor = textColor
subtitleLbl.font = UIFont.systemFont(ofSize: subtitleSize, weight: .semibold)
subtitleLbl.adjustsFontSizeToFitWidth = true
subtitleLbl.minimumScaleFactor = 0.1
subtitleLbl.lineBreakMode = .byTruncatingTail
subtitleLbl.numberOfLines = 0



titleLbl.frame = CGRect(x: X(insets), y: X(insets), width: X(100-(insets*2)), height: Y(5))
titleLbl.text = title.uppercased()
titleLbl.frame = CGRect(x: X(insets), y: Y(2, from: subtitleLbl), width: X(100-(insets*2)), height: Y(15))
titleLbl.textColor = textColor
titleLbl.font = UIFont.systemFont(ofSize: 40, weight: .semibold)
titleLbl.shadowColor = UIColor.black
titleLbl.shadowOffset = CGSize.zero
titleLbl.text = title
titleLbl.font = UIFont.systemFont(ofSize: titleSize, weight: .bold)
titleLbl.adjustsFontSizeToFitWidth = true
titleLbl.minimumScaleFactor = 0.1
titleLbl.lineBreakMode = .byTruncatingTail
titleLbl.numberOfLines = 0


subtitleLbl.frame = CGRect(x: X(insets), y: Y(2, from: titleLbl), width: X(100-(insets*2)), height: Y(15))
subtitleLbl.textColor = textColor
subtitleLbl.text = subtitle
subtitleLbl.font = UIFont.systemFont(ofSize: self.maxTitleFontSize, weight: .bold)
subtitleLbl.adjustsFontSizeToFitWidth = true
subtitleLbl.minimumScaleFactor = 0.1
subtitleLbl.lineBreakMode = .byTruncatingTail
subtitleLbl.numberOfLines = 2
subtitleLbl.sizeToFit()
titleLbl.numberOfLines = 2
titleLbl.sizeToFit()
//subtitleLbl.backgroundColor = UIColor.blue

blurV.frame = CGRect(x: 0, y: 0, width: rect.width, height: Y(insets*2) + titleLbl.frame.size.height + subtitleLbl.frame.height)
blurV.frame = CGRect(x: 0, y: 0, width: rect.width, height: Y(insets*2) + subtitleLbl.frame.size.height + titleLbl.frame.height)
let blur = UIBlurEffect(style: blurEffect)
blurV.effect = blur

vibrancyV.frame = blurV.frame
}

override func cardTapped() {
super.cardTapped()
delegate?.cardDidTapInside?(card: self)

}
}


28 changes: 15 additions & 13 deletions Cards/CardGroupSliding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ import UIKit

@IBDesignable class CardGroupSliding: CardGroup {

// SB Vars
@IBInspectable var iconsSize: CGFloat = 80
@IBInspectable var iconsRadius: CGFloat = 40

var icons: [UIImage]?

final let CellID = "SlidingCVCell"
var slidingCV: UICollectionView!
var timer = Timer()
var w: CGFloat = 0
// Priv vars
private final let CellID = "SlidingCVCell"
internal var slidingCV: UICollectionView!
internal var timer = Timer()
internal var w: CGFloat = 0

override init(frame: CGRect) {
super.init(frame: frame)
initialize()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}

override func initialize() {
super.initialize()

let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
Expand All @@ -35,8 +43,8 @@ import UIKit
slidingCV.backgroundColor = UIColor.clear
slidingCV.isUserInteractionEnabled = false

backgroundIV.addSubview(titleLbl)
backgroundIV.addSubview(subtitleLbl)
backgroundIV.addSubview(titleLbl)
backgroundIV.addSubview(slidingCV)
blurV.removeFromSuperview()

Expand All @@ -54,10 +62,9 @@ import UIKit
func RevY(_ percentage: CGFloat, height: CGFloat) -> CGFloat { return (rect.height - percentage*rect.height/100) - height }
super.draw(rect)

//subtitleLbl.frame = CGRect(x: X(insets), y: Y(1, from: titleLbl), width: X(100 - (2 * insets)), height: Y(10))
titleLbl.textColor = textColor.withAlphaComponent(0.3)
subtitleLbl.textColor = textColor.withAlphaComponent(0.4)

slidingCV.frame = CGRect(x: 0, y: Y(8, from: subtitleLbl), width: rect.width, height: Y(65))
slidingCV.frame = CGRect(x: 0, y: RevY(insets*(rect.width/rect.height), height: Y(60)), width: rect.width, height: Y(60))

}

Expand Down Expand Up @@ -151,11 +158,6 @@ extension CardGroupSliding: UICollectionViewDelegateFlowLayout{

}

extension CardGroupSliding: UICollectionViewDelegate {


}




Expand Down
Loading

0 comments on commit e4ab6f2

Please sign in to comment.