Skip to content

Commit

Permalink
Implemented circle button
Browse files Browse the repository at this point in the history
  • Loading branch information
fakerabbit committed Mar 3, 2017
1 parent 099c18f commit f0f969d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Memoria.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
AC34D5C21E68AEFB00120C62 /* LearnCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC34D5C11E68AEFB00120C62 /* LearnCell.swift */; };
AC34D5C41E68B4DB00120C62 /* RoundTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC34D5C31E68B4DB00120C62 /* RoundTextView.swift */; };
AC34D5C61E68E61300120C62 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC34D5C51E68E61300120C62 /* Extensions.swift */; };
AC5692D71E691A6E004EFC73 /* CircleBtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5692D61E691A6E004EFC73 /* CircleBtn.swift */; };
AC7CDB6D1E67C7C30025FEFE /* Botdoh.otf in Resources */ = {isa = PBXBuildFile; fileRef = AC7CDB6A1E67C7C30025FEFE /* Botdoh.otf */; };
AC7CDB6E1E67C7C30025FEFE /* Nexa Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = AC7CDB6B1E67C7C30025FEFE /* Nexa Bold.otf */; };
AC7CDB6F1E67C7C30025FEFE /* Nexa Light.otf in Resources */ = {isa = PBXBuildFile; fileRef = AC7CDB6C1E67C7C30025FEFE /* Nexa Light.otf */; };
Expand All @@ -29,6 +30,7 @@
AC34D5C11E68AEFB00120C62 /* LearnCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LearnCell.swift; sourceTree = "<group>"; };
AC34D5C31E68B4DB00120C62 /* RoundTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundTextView.swift; sourceTree = "<group>"; };
AC34D5C51E68E61300120C62 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
AC5692D61E691A6E004EFC73 /* CircleBtn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CircleBtn.swift; sourceTree = "<group>"; };
AC7CDB6A1E67C7C30025FEFE /* Botdoh.otf */ = {isa = PBXFileReference; lastKnownFileType = file; name = Botdoh.otf; path = Assets/Fonts/Botdoh.otf; sourceTree = "<group>"; };
AC7CDB6B1E67C7C30025FEFE /* Nexa Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Nexa Bold.otf"; path = "Assets/Fonts/Nexa Bold.otf"; sourceTree = "<group>"; };
AC7CDB6C1E67C7C30025FEFE /* Nexa Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "Nexa Light.otf"; path = "Assets/Fonts/Nexa Light.otf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +88,7 @@
AC9CBB471E64E4EA00C634F3 /* MemoriaVC.swift */,
AC34D5C31E68B4DB00120C62 /* RoundTextView.swift */,
AC34D5C51E68E61300120C62 /* Extensions.swift */,
AC5692D61E691A6E004EFC73 /* CircleBtn.swift */,
);
name = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -200,6 +203,7 @@
AC9CBB4E1E64E4EA00C634F3 /* NavController.swift in Sources */,
AC9CBB4B1E64E4EA00C634F3 /* DataMgr.swift in Sources */,
AC9CBB4D1E64E4EA00C634F3 /* MemoriaVC.swift in Sources */,
AC5692D71E691A6E004EFC73 /* CircleBtn.swift in Sources */,
AC9CBB4F1E64E4EA00C634F3 /* LearnVC.swift in Sources */,
AC34D5C21E68AEFB00120C62 /* LearnCell.swift in Sources */,
AC34D5C41E68B4DB00120C62 /* RoundTextView.swift in Sources */,
Expand Down
62 changes: 62 additions & 0 deletions Memoria/CircleBtn.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// CircleBtn.swift
// Memoria
//
// Created by Mirko Justiniano on 3/2/17.
// Copyright © 2017 MM. All rights reserved.
//

import Foundation
import UIKit

class CircleBtn: UIButton {

var title: String! {
didSet {
self.titleLbl.text = title
self.titleLbl.sizeToFit()
self.layoutIfNeeded()
}
}

private lazy var titleLbl: UILabel! = {
let lbl = UILabel(frame: CGRect.zero)
lbl.font = Utils.buttonFont()
lbl.textColor = Utils.darkColor()
return lbl
}()

// MARK:- Init
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.white
self.layer.shadowOpacity = 0.7
self.layer.shadowColor = Utils.cardColor().cgColor
self.addSubview(titleLbl)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override var isHighlighted: Bool {
didSet {
switch isHighlighted {
case true:
self.backgroundColor = Utils.cardColor()
case false:
self.backgroundColor = UIColor.white
}
}
}

// MARK:- Layout
override func layoutSubviews() {
super.layoutSubviews()
let w = self.frame.size.width
let h = self.frame.size.height
self.layer.cornerRadius = w/2;
self.layer.shadowRadius = w/2;
titleLbl.frame = CGRect(x: w/2 - titleLbl.frame.size.width/2, y: h/2 - titleLbl.frame.size.height/2 + 5, width: titleLbl.frame.size.width, height: titleLbl.frame.size.height)
}
}
2 changes: 1 addition & 1 deletion Memoria/LearnCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class LearnCell: UICollectionViewCell {
self.textView.textColor = Utils.cardColor()
self.textView.layer.borderColor = Utils.cardColor().cgColor

let timer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false) { [weak self] (timer) in
let timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { [weak self] (timer) in

self?.textView.textColor = Utils.creamColor()
self?.textView.layer.borderColor = Utils.creamColor().cgColor
Expand Down
3 changes: 3 additions & 0 deletions Memoria/LearnVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class LearnVC: MemoriaVC {
learnView.onCell = { category in
debugPrint("category: \(category)")
}
learnView.onAdd = { view in
debugPrint("add...")
}
}

override func didReceiveMemoryWarning() {
Expand Down
19 changes: 19 additions & 0 deletions Memoria/LearnView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class LearnView: UIView, UICollectionViewDelegate, UICollectionViewDataSource, U
typealias LearnViewOnTouch = (Category) -> Void
var onCell: LearnViewOnTouch = { category in }

typealias LearnViewOnAdd = (LearnView) -> Void
var onAdd: LearnViewOnAdd = { view in }

lazy var gradientLayer: CAGradientLayer! = {
let view = CAGradientLayer()
view.frame = CGRect.zero
Expand Down Expand Up @@ -54,6 +57,12 @@ class LearnView: UIView, UICollectionViewDelegate, UICollectionViewDataSource, U
lbl.sizeToFit()
return lbl
}()
private lazy var addBtn: CircleBtn! = {
let btn = CircleBtn(frame: CGRect.zero)
btn.title = "+"
btn.addTarget(self, action: #selector(onAdd(_:)), for: .touchUpInside)
return btn
}()

/*
* MARK:- Init
Expand All @@ -66,20 +75,24 @@ class LearnView: UIView, UICollectionViewDelegate, UICollectionViewDataSource, U
self.layer.addSublayer(gradientLayer)
self.addSubview(collectionView)
self.addSubview(titleLbl)
self.addSubview(addBtn)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK:- Layout
override func layoutSubviews() {
super.layoutSubviews()
let w = self.frame.size.width
let h = self.frame.size.height
let pad: CGFloat = 100
let btnS: CGFloat = 70
gradientLayer.frame = self.bounds
collectionView.frame = CGRect(x: 0, y: pad, width: w, height: h - pad)
titleLbl.frame = CGRect(x: 10, y: pad - titleLbl.frame.size.height, width: titleLbl.frame.size.width, height: titleLbl.frame.size.height)
addBtn.frame = CGRect(x: w/2 - btnS/2, y: h - (btnS + 10), width: btnS, height: btnS)
}

/*
Expand Down Expand Up @@ -137,6 +150,12 @@ class LearnView: UIView, UICollectionViewDelegate, UICollectionViewDataSource, U
return size
}

// MARK:- Private

func onAdd(_ sender : UIButton) {
self.onAdd(self)
}

// MARK:- Animations

func randomColors() -> [CGColor] {
Expand Down
4 changes: 4 additions & 0 deletions Memoria/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ struct Utils {
return UIFont(name: "NexaBold", size: 18.0)!
}

static func buttonFont() -> UIFont {
return UIFont(name: "NexaBold", size: 50.0)!
}

/*
* MARK:- COLORS
*/
Expand Down

0 comments on commit f0f969d

Please sign in to comment.