diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index e636683..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/Cards/Card.swift b/Cards/Card.swift index c12533e..d785e2e 100644 --- a/Cards/Card.swift +++ b/Cards/Card.swift @@ -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 { @@ -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) } @@ -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 @@ -82,8 +83,6 @@ protocol CardDelegate { }) } } - - } diff --git a/Cards/CardArticle.swift b/Cards/CardArticle.swift index 80f2153..24d74d0 100644 --- a/Cards/CardArticle.swift +++ b/Cards/CardArticle.swift @@ -12,7 +12,9 @@ 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 @@ -20,21 +22,26 @@ import UIKit 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) - } @@ -66,7 +73,7 @@ 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 @@ -74,10 +81,10 @@ import UIKit 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 @@ -90,7 +97,7 @@ import UIKit override func cardTapped() { super.cardTapped() - delegate?.cardDidTapInside(card: self) + delegate?.cardDidTapInside?(card: self) } } diff --git a/Cards/CardGroup.swift b/Cards/CardGroup.swift index ebbd230..1b17c7d 100644 --- a/Cards/CardGroup.swift +++ b/Cards/CardGroup.swift @@ -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 @@ -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) + + } } diff --git a/Cards/CardGroupSliding.swift b/Cards/CardGroupSliding.swift index 46af826..12bee0d 100644 --- a/Cards/CardGroupSliding.swift +++ b/Cards/CardGroupSliding.swift @@ -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 @@ -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() @@ -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)) } @@ -151,11 +158,6 @@ extension CardGroupSliding: UICollectionViewDelegateFlowLayout{ } -extension CardGroupSliding: UICollectionViewDelegate { - - -} - diff --git a/Cards/CardHighlight.swift b/Cards/CardHighlight.swift index 3cab1c0..eb5957a 100644 --- a/Cards/CardHighlight.swift +++ b/Cards/CardHighlight.swift @@ -11,9 +11,9 @@ import UIKit @IBDesignable class CardHighlight: Card { // SB Vars - @IBInspectable var title: String = "gioco del giorno" + @IBInspectable var title: String = "welcome to cards XI !" @IBInspectable var itemTitle: String = "Flappy Bird" - @IBInspectable var ItemTitleSize: CGFloat = 14 + @IBInspectable var itemTitleSize: CGFloat = 14 @IBInspectable var itemSubtitle: String = "Flap that !" @IBInspectable var itemSubtitleSize: CGFloat = 12 @IBInspectable var icon: UIImage? @@ -23,20 +23,26 @@ import UIKit var delegate: CardDelegate? //Priv Vars - var iconIV = UIImageView() - var actionBtn = UIButton() - var titleLbl = UILabel () - var itemTitleLbl = UILabel() - var itemSubtitleLbl = UILabel() - var lightColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1) - var bgIconIV = UIImageView() + internal var iconIV = UIImageView() + internal var actionBtn = UIButton() + internal var titleLbl = UILabel () + internal var itemTitleLbl = UILabel() + internal var itemSubtitleLbl = UILabel() + internal var lightColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1) + internal var bgIconIV = UIImageView() // 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(iconIV) backgroundIV.addSubview(titleLbl) @@ -87,7 +93,7 @@ import UIKit itemTitleLbl.frame = CGRect(x: X(insets), y: RevY(17, height: Y(8)) + X(insets), width: X(80) - btnWidth, height: Y(8)) itemTitleLbl.textColor = textColor itemTitleLbl.text = itemTitle - itemTitleLbl.font = UIFont.boldSystemFont(ofSize: ItemTitleSize) + itemTitleLbl.font = UIFont.boldSystemFont(ofSize: itemTitleSize) itemTitleLbl.adjustsFontSizeToFitWidth = true itemTitleLbl.minimumScaleFactor = 0.1 itemTitleLbl.lineBreakMode = .byTruncatingTail @@ -103,7 +109,7 @@ import UIKit itemSubtitleLbl.numberOfLines = 2 itemSubtitleLbl.sizeToFit() - actionBtn.frame = CGRect(x: RevX(insets, width: btnWidth), y: RevY(insets+2, height: 36), width: btnWidth, height: 28) + actionBtn.frame = CGRect(x: RevX(insets, width: btnWidth), y: RevY(insets, height: 32), width: btnWidth, height: 32) actionBtn.backgroundColor = UIColor.clear actionBtn.layer.backgroundColor = lightColor.cgColor actionBtn.layer.cornerRadius = actionBtn.layer.bounds.height/2 @@ -111,8 +117,14 @@ import UIKit actionBtn.setAttributedTitle(btnTitle, for: .normal) actionBtn.addTarget(self, action: #selector(buttonTapped), for: UIControlEvents.touchUpInside) + backgroundIV.bringSubview(toFront: titleLbl) + } + override func cardTapped() { + super.cardTapped() + delegate?.cardDidTapInside?(card: self) + } //Actions @objc func buttonTapped(){ @@ -124,7 +136,7 @@ import UIKit self.actionBtn.transform = CGAffineTransform.identity }) } - delegate?.cardDidTapButton(button: actionBtn) + delegate?.cardDidTapButton?(button: actionBtn) } diff --git a/Images/GetStarted.png b/Images/GetStarted.png new file mode 100644 index 0000000..0c55f67 Binary files /dev/null and b/Images/GetStarted.png differ diff --git a/Images/Overview.png b/Images/Overview.png new file mode 100644 index 0000000..b65a4a1 Binary files /dev/null and b/Images/Overview.png differ diff --git a/README.md b/README.md index 453d0ce..a10c924 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,71 @@ -## Cards -Awesome iOS 11 AppStore's Card Views. +[![CocoaPods Version](https://img.shields.io/cocoapods/v/Cards.svg?style=flat)](http://cocoadocs.org/docsets/Cards) +[![Platform](https://img.shields.io/cocoapods/p/Cards.svg?style=flat)](http://cocoadocs.org/docsets/Cards) +![Cards](https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/Logo.png) + +Cards brings to XCode the card views that you can see on the new iOS XI Appstore. + +## Getting Started + +### Storyboard +- Go to the **main.storyboard** and add a **blank UIView** +- Open the **Identity Inspector** and type 'CardHighligth' the **'class' field** +- Switch to the **Attributes Inspector** and **configure** it as you like. + +### Code +```swift +// Aspect Ratio of 5:6 is preferred +let card = CardHighlight(frame: CGRect(x: 100, y: 100, width: 200, height: 240)) +card.bgColor = UIColor(red: 0, green: 94/255, blue: 112/255, alpha: 1) +card.bgImage = UIImage(named: "flBackground") +card.icon = UIImage(named: "flappy") +card.title = "Welcome to XI Cards !" +card.itemTitle = "Flappy Bird" +card.itemSubtitle = "Flap That !" +view.addSubview(card) +``` + +![GetStarted](https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/GetStarted.png) + +## Prerequisites + +- **XCode 9.0** or newer +- **Swift 4.0** + +## Installation + +### Cocoapods +``` +use_frameworks! +pod 'Cards' +``` +### Manual +- **Download** the repo +- ⌘C ⌘V the **'Cards' folder** in your project +- In your **Project's Info** go to '**Build Phases**' +- Open '**Compile Sources**' and **add all the files** in the folder + +## Overview + +![Overview](https://raw.githubusercontent.com/PaoloCuscela/Cards/master/Images/Overview.png) + +## Customization + +```swift +//Shadow settings +var shadowBlur: CGFloat +var shadowOpacity: Float +var shadowColor: UIColor +//Use those for the background instead of UIView.backgroundColor +var bgImage: UIImage? +var bgColor: UIColor + +var textColor: UIColor //Color used for the labels +var insets: CGFloat //Spacing between content and card borders +var cardRadius: CGFloat //Corner radius of the card +var icons: [UIImage]? //DataSource for CardGroupSliding +var blurEffect: UIBlurEffectStyle //Blur effect of CardGroup +``` + +## License + +Cards is released under the [MIT License](LICENSE). \ No newline at end of file diff --git a/Source/.DS_Store b/Source/.DS_Store deleted file mode 100644 index 80c69ea..0000000 Binary files a/Source/.DS_Store and /dev/null differ diff --git a/Source/Cards.xcodeproj/project.pbxproj b/Source/Cards.xcodeproj/project.pbxproj index db8cdf0..6be60e3 100644 --- a/Source/Cards.xcodeproj/project.pbxproj +++ b/Source/Cards.xcodeproj/project.pbxproj @@ -11,12 +11,12 @@ 524AFF881F86424C00A137F7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 524AFF871F86424C00A137F7 /* ViewController.swift */; }; 524AFF8B1F86424C00A137F7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 524AFF891F86424C00A137F7 /* Main.storyboard */; }; 524AFF901F86424C00A137F7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 524AFF8E1F86424C00A137F7 /* LaunchScreen.storyboard */; }; - 525383141F8B54AE0070C567 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525383131F8B54AE0070C567 /* Card.swift */; }; 5276B28C1F88C35E00A30082 /* CardHighlight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5276B28B1F88C35E00A30082 /* CardHighlight.swift */; }; 5276B28E1F8A564900A30082 /* CardGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5276B28D1F8A564900A30082 /* CardGroup.swift */; }; 5276B2901F8A633400A30082 /* CardArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5276B28F1F8A633400A30082 /* CardArticle.swift */; }; 5276B2931F8A6BB000A30082 /* CardGroupSliding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5276B2921F8A6BB000A30082 /* CardGroupSliding.swift */; }; 52CBD33E1F8D32B6008959A0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 52CBD33D1F8D32B6008959A0 /* Assets.xcassets */; }; + 52FA8B941F8E87A10000B5A2 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525383131F8B54AE0070C567 /* Card.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -167,9 +167,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 52FA8B941F8E87A10000B5A2 /* Card.swift in Sources */, 524AFF881F86424C00A137F7 /* ViewController.swift in Sources */, 5276B28E1F8A564900A30082 /* CardGroup.swift in Sources */, - 525383141F8B54AE0070C567 /* Card.swift in Sources */, 5276B2931F8A6BB000A30082 /* CardGroupSliding.swift in Sources */, 5276B28C1F88C35E00A30082 /* CardHighlight.swift in Sources */, 524AFF861F86424C00A137F7 /* AppDelegate.swift in Sources */, @@ -313,7 +313,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 4B98PNC6BV; INFOPLIST_FILE = Cards/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.paolocuscela.Cards; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -329,7 +329,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 4B98PNC6BV; INFOPLIST_FILE = Cards/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.paolocuscela.Cards; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Source/Cards.xcodeproj/project.xcworkspace/xcuserdata/Paolo.xcuserdatad/UserInterfaceState.xcuserstate b/Source/Cards.xcodeproj/project.xcworkspace/xcuserdata/Paolo.xcuserdatad/UserInterfaceState.xcuserstate index 044546a..d5c0540 100644 Binary files a/Source/Cards.xcodeproj/project.xcworkspace/xcuserdata/Paolo.xcuserdatad/UserInterfaceState.xcuserstate and b/Source/Cards.xcodeproj/project.xcworkspace/xcuserdata/Paolo.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Source/Cards/.DS_Store b/Source/Cards/.DS_Store index 293ff4c..09ac390 100644 Binary files a/Source/Cards/.DS_Store and b/Source/Cards/.DS_Store differ diff --git a/Source/Cards/Assets.xcassets/math.imageset/Contents.json b/Source/Cards/Assets.xcassets/grBackground.imageset/Contents.json similarity index 100% rename from Source/Cards/Assets.xcassets/math.imageset/Contents.json rename to Source/Cards/Assets.xcassets/grBackground.imageset/Contents.json diff --git a/Source/Cards/Assets.xcassets/math.imageset/math_equations-wallpaper-800x480.jpg b/Source/Cards/Assets.xcassets/grBackground.imageset/math_equations-wallpaper-800x480.jpg similarity index 100% rename from Source/Cards/Assets.xcassets/math.imageset/math_equations-wallpaper-800x480.jpg rename to Source/Cards/Assets.xcassets/grBackground.imageset/math_equations-wallpaper-800x480.jpg diff --git a/Source/Cards/Cards/Card.swift b/Source/Cards/Cards/Card.swift index c12533e..d785e2e 100644 --- a/Source/Cards/Cards/Card.swift +++ b/Source/Cards/Cards/Card.swift @@ -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 { @@ -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) } @@ -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 @@ -82,8 +83,6 @@ protocol CardDelegate { }) } } - - } diff --git a/Source/Cards/Cards/CardArticle.swift b/Source/Cards/Cards/CardArticle.swift index 80f2153..24d74d0 100644 --- a/Source/Cards/Cards/CardArticle.swift +++ b/Source/Cards/Cards/CardArticle.swift @@ -12,7 +12,9 @@ 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 @@ -20,21 +22,26 @@ import UIKit 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) - } @@ -66,7 +73,7 @@ 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 @@ -74,10 +81,10 @@ import UIKit 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 @@ -90,7 +97,7 @@ import UIKit override func cardTapped() { super.cardTapped() - delegate?.cardDidTapInside(card: self) + delegate?.cardDidTapInside?(card: self) } } diff --git a/Source/Cards/Cards/CardGroup.swift b/Source/Cards/Cards/CardGroup.swift index ebbd230..1b17c7d 100644 --- a/Source/Cards/Cards/CardGroup.swift +++ b/Source/Cards/Cards/CardGroup.swift @@ -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 @@ -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) + + } } diff --git a/Source/Cards/Cards/CardGroupSliding.swift b/Source/Cards/Cards/CardGroupSliding.swift index 46af826..12bee0d 100644 --- a/Source/Cards/Cards/CardGroupSliding.swift +++ b/Source/Cards/Cards/CardGroupSliding.swift @@ -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 @@ -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() @@ -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)) } @@ -151,11 +158,6 @@ extension CardGroupSliding: UICollectionViewDelegateFlowLayout{ } -extension CardGroupSliding: UICollectionViewDelegate { - - -} - diff --git a/Source/Cards/Cards/CardHighlight.swift b/Source/Cards/Cards/CardHighlight.swift index 3cab1c0..eb5957a 100644 --- a/Source/Cards/Cards/CardHighlight.swift +++ b/Source/Cards/Cards/CardHighlight.swift @@ -11,9 +11,9 @@ import UIKit @IBDesignable class CardHighlight: Card { // SB Vars - @IBInspectable var title: String = "gioco del giorno" + @IBInspectable var title: String = "welcome to cards XI !" @IBInspectable var itemTitle: String = "Flappy Bird" - @IBInspectable var ItemTitleSize: CGFloat = 14 + @IBInspectable var itemTitleSize: CGFloat = 14 @IBInspectable var itemSubtitle: String = "Flap that !" @IBInspectable var itemSubtitleSize: CGFloat = 12 @IBInspectable var icon: UIImage? @@ -23,20 +23,26 @@ import UIKit var delegate: CardDelegate? //Priv Vars - var iconIV = UIImageView() - var actionBtn = UIButton() - var titleLbl = UILabel () - var itemTitleLbl = UILabel() - var itemSubtitleLbl = UILabel() - var lightColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1) - var bgIconIV = UIImageView() + internal var iconIV = UIImageView() + internal var actionBtn = UIButton() + internal var titleLbl = UILabel () + internal var itemTitleLbl = UILabel() + internal var itemSubtitleLbl = UILabel() + internal var lightColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1) + internal var bgIconIV = UIImageView() // 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(iconIV) backgroundIV.addSubview(titleLbl) @@ -87,7 +93,7 @@ import UIKit itemTitleLbl.frame = CGRect(x: X(insets), y: RevY(17, height: Y(8)) + X(insets), width: X(80) - btnWidth, height: Y(8)) itemTitleLbl.textColor = textColor itemTitleLbl.text = itemTitle - itemTitleLbl.font = UIFont.boldSystemFont(ofSize: ItemTitleSize) + itemTitleLbl.font = UIFont.boldSystemFont(ofSize: itemTitleSize) itemTitleLbl.adjustsFontSizeToFitWidth = true itemTitleLbl.minimumScaleFactor = 0.1 itemTitleLbl.lineBreakMode = .byTruncatingTail @@ -103,7 +109,7 @@ import UIKit itemSubtitleLbl.numberOfLines = 2 itemSubtitleLbl.sizeToFit() - actionBtn.frame = CGRect(x: RevX(insets, width: btnWidth), y: RevY(insets+2, height: 36), width: btnWidth, height: 28) + actionBtn.frame = CGRect(x: RevX(insets, width: btnWidth), y: RevY(insets, height: 32), width: btnWidth, height: 32) actionBtn.backgroundColor = UIColor.clear actionBtn.layer.backgroundColor = lightColor.cgColor actionBtn.layer.cornerRadius = actionBtn.layer.bounds.height/2 @@ -111,8 +117,14 @@ import UIKit actionBtn.setAttributedTitle(btnTitle, for: .normal) actionBtn.addTarget(self, action: #selector(buttonTapped), for: UIControlEvents.touchUpInside) + backgroundIV.bringSubview(toFront: titleLbl) + } + override func cardTapped() { + super.cardTapped() + delegate?.cardDidTapInside?(card: self) + } //Actions @objc func buttonTapped(){ @@ -124,7 +136,7 @@ import UIKit self.actionBtn.transform = CGAffineTransform.identity }) } - delegate?.cardDidTapButton(button: actionBtn) + delegate?.cardDidTapButton?(button: actionBtn) } diff --git a/Source/Cards/SBs/Base.lproj/Main.storyboard b/Source/Cards/SBs/Base.lproj/Main.storyboard index f1dec1f..84a9f41 100644 --- a/Source/Cards/SBs/Base.lproj/Main.storyboard +++ b/Source/Cards/SBs/Base.lproj/Main.storyboard @@ -20,7 +20,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -73,6 +73,11 @@ + + + + + @@ -81,8 +86,8 @@ - + - + diff --git a/Source/Cards/ViewController.swift b/Source/Cards/ViewController.swift index 281bb65..40debb2 100644 --- a/Source/Cards/ViewController.swift +++ b/Source/Cards/ViewController.swift @@ -10,29 +10,45 @@ import UIKit class ViewController: UIViewController { - // @IBOutlet weak var card: CardGroupSliding! override func viewDidLoad() { super.viewDidLoad() - _ = [ - + let icons: [UIImage] = [ + + UIImage(named: "grBackground")!, UIImage(named: "background")!, - UIImage(named: "Icon")!, - UIImage(named: "math")!, - UIImage(named: "mvBackground")!, - UIImage(named: "math")! + UIImage(named: "flappy")!, + UIImage(named: "flBackground")!, + UIImage(named: "icon")!, + UIImage(named: "mvBackground")! + ] - //card.icons = icons + // Aspect Ratio of 5:6 is preferred + let card = CardGroupSliding(frame: CGRect(x: 50, y: 50, width: 300 , height: 360)) + card.textColor = UIColor.black + card.iconsSize = 60 + card.iconsRadius = 30 + card.icons = icons + view.addSubview(card) + + card.delegate = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. } +} - +extension ViewController: CardDelegate { + + func cardDidTapInside(card: Card) { + if let cardGS = card as? CardGroupSliding { + print("Card with title: \(cardGS.title) has ben tapped.") + } + } + }