Commit 54b91588 by Daniel Dahan

updated Pulse and Divider to be accessible through Storyboards

parent ed5c1030
......@@ -58,12 +58,12 @@ class ViewController: UIViewController {
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.white)
favoriteButton.pulse.color = Color.white
favoriteButton.pulseColor = Color.white
}
private func prepareShareButton() {
shareButton = IconButton(image: Icon.cm.share, tintColor: Color.white)
shareButton.pulse.color = Color.white
shareButton.pulseColor = Color.white
}
private func prepareTitleLabel() {
......
......@@ -80,7 +80,7 @@ class ViewController: UIViewController {
private func prepareRaisedButton() {
let button = RaisedButton(title: "Raised Button", titleColor: Color.white)
button.pulse.color = Color.white
button.pulseColor = Color.white
button.backgroundColor = Color.blue.base
view.layout(button)
......
......@@ -2,6 +2,16 @@
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
......@@ -32,6 +42,16 @@
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
......@@ -59,6 +79,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
......
......@@ -77,7 +77,7 @@ class RootViewController: UIViewController {
private func prepareNextButton() {
nextButton = FlatButton()
nextButton.pulse.animation = .none
nextButton.pulseAnimation = .none
nextButton.addTarget(self, action: #selector(handleNextButton), for: .touchUpInside)
view.layout(nextButton).edges()
}
......
......@@ -51,7 +51,7 @@ class RootViewController: UIViewController {
private func prepareUndoButton() {
undoButton = FlatButton(title: "Undo", titleColor: Color.yellow.base)
undoButton.pulse.animation = .backing
undoButton.pulseAnimation = .backing
undoButton.titleLabel?.font = RobotoFont.regular(with: 14)
}
......
......@@ -48,15 +48,15 @@ class ViewController: UIViewController {
private func prepareButtons() {
let btn1 = FlatButton(title: "Library", titleColor: Color.blueGrey.base)
btn1.pulse.animation = .none
btn1.pulseAnimation = .none
buttons.append(btn1)
let btn2 = FlatButton(title: "Photo", titleColor: Color.blueGrey.base)
btn2.pulse.animation = .none
btn2.pulseAnimation = .none
buttons.append(btn2)
let btn3 = FlatButton(title: "Video", titleColor: Color.blueGrey.base)
btn3.pulse.animation = .none
btn3.pulseAnimation = .none
buttons.append(btn3)
}
......
......@@ -14,6 +14,19 @@
9A0572981D99E64100341332 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A0572961D99E64100341332 /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
9690B4151D99FF2700E7F42A /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9A05728A1D99E64100341332 /* Button.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Button.app; sourceTree = BUILT_PRODUCTS_DIR; };
9A05728D1D99E64100341332 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
......@@ -74,6 +87,7 @@
9A0572861D99E64100341332 /* Sources */,
9A0572871D99E64100341332 /* Frameworks */,
9A0572881D99E64100341332 /* Resources */,
9690B4151D99FF2700E7F42A /* Embed Frameworks */,
);
buildRules = (
);
......@@ -96,7 +110,6 @@
TargetAttributes = {
9A0572891D99E64100341332 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 5YZ5P93LKC;
ProvisioningStyle = Automatic;
};
};
......@@ -259,7 +272,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5YZ5P93LKC;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Button/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cosmicmind.Button;
......@@ -272,7 +285,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 5YZ5P93LKC;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Button/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cosmicmind.Button;
......
......@@ -32,36 +32,24 @@ import UIKit
import Material
class ViewController: UIViewController {
// ivars
@IBOutlet weak var fabButton: FabButton!
@IBOutlet weak var iconButton: IconButton!
/**
@name viewDidLoad()
*/
override func viewDidLoad() {
super.viewDidLoad()
prepareFabButton()
prepareIconButton()
}
}
// Preparation
extension ViewController {
/**
@name prepareFabButton()
*/
func prepareFabButton() {
fabButton.setImage(Icon.edit, for: .normal)
fabButton.image = Icon.cm.add
fabButton.pulseColor = Color.white
}
/**
@name prepareIconButton()
*/
func prepareIconButton() {
iconButton.setImage(Icon.search, for: .normal)
iconButton.image = Icon.search
iconButton.pulseColor = Color.blue.base
}
}
......@@ -74,5 +74,12 @@
location = "group:Examples/Programmatic/View/View.xcodeproj">
</FileRef>
</Group>
<Group
location = "container:"
name = "Storyboards">
<FileRef
location = "group:Examples/Storyboards/Button/Button.xcodeproj">
</FileRef>
</Group>
</Group>
</Workspace>
......@@ -102,7 +102,39 @@ open class Bar: View {
}
/// Divider layer.
open internal(set) var divider: Divider!
internal lazy var divider: Divider = Divider(view: self)
/// Divider color.
@IBInspectable
open var dividerColor: UIColor? {
get {
return divider.color
}
set(value) {
divider.color = value
}
}
/// Divider animation.
open var dividerAlignment: DividerAlignment {
get {
return divider.alignment
}
set(value) {
divider.alignment = value
}
}
/// Divider height.
@IBInspectable
open var dividerHeight: CGFloat {
get {
return divider.height
}
set(value) {
divider.height = value
}
}
/// ContentView that holds the any desired subviews.
open private(set) lazy var contentView = View()
......@@ -233,16 +265,10 @@ open class Bar: View {
open override func prepare() {
super.prepare()
prepareContentView()
prepareDivider()
}
/// Prepares the contentView.
private func prepareContentView() {
contentView.backgroundColor = nil
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
}
......@@ -123,7 +123,7 @@ open class BottomTabBar: UITabBar {
*/
public func prepare() {
depthPreset = .depth1
divider.alignment = .top
dividerAlignment = .top
contentScaleFactor = Device.scale
backgroundColor = Color.white
let image = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
......@@ -137,7 +137,7 @@ private var TabBarKey: UInt8 = 0
extension UITabBar {
/// TabBarItem reference.
public internal(set) var divider: Divider! {
internal private(set) var divider: Divider! {
get {
return AssociatedObject(base: self, key: &TabBarKey) {
return Divider(view: self)
......@@ -147,5 +147,37 @@ extension UITabBar {
AssociateObject(base: self, key: &TabBarKey, value: value)
}
}
/// Divider color.
@IBInspectable
open var dividerColor: UIColor? {
get {
return divider.color
}
set(value) {
divider.color = value
}
}
/// Divider animation.
open var dividerAlignment: DividerAlignment {
get {
return divider.alignment
}
set(value) {
divider.alignment = value
}
}
/// Divider height.
@IBInspectable
open var dividerHeight: CGFloat {
get {
return divider.height
}
set(value) {
divider.height = value
}
}
}
......@@ -41,9 +41,40 @@ open class Button: UIButton {
open private(set) lazy var visualLayer = CAShapeLayer()
/// A Pulse reference.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
internal private(set) lazy var pulse: Pulse = Pulse()
/// PulseAnimation value.
open var pulseAnimation: PulseAnimation {
get {
return pulse.animation
}
set(value) {
pulse.animation = value
}
}
/// PulseAnimation color.
@IBInspectable
open var pulseColor: UIColor {
get {
return pulse.color
}
set(value) {
pulse.color = value
}
}
/// Pulse opacity.
@IBInspectable
open var pulseOpacity: CGFloat {
get {
return pulse.opacity
}
set(value) {
pulse.opacity = value
}
}
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
open override var backgroundColor: UIColor? {
......
......@@ -180,7 +180,7 @@ open class Card: PulseView {
open override func prepare() {
super.prepare()
depthPreset = .depth1
pulse.animation = .none
pulseAnimation = .none
}
/**
......
......@@ -41,8 +41,39 @@ open class CollectionReusableView: UICollectionReusableView {
open private(set) lazy var visualLayer = CAShapeLayer()
/// A Pulse reference.
internal private(set) lazy var pulse: Pulse = Pulse()
/// PulseAnimation value.
open var pulseAnimation: PulseAnimation {
get {
return pulse.animation
}
set(value) {
pulse.animation = value
}
}
/// PulseAnimation color.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
open var pulseColor: UIColor {
get {
return pulse.color
}
set(value) {
pulse.color = value
}
}
/// Pulse opacity.
@IBInspectable
open var pulseOpacity: CGFloat {
get {
return pulse.opacity
}
set(value) {
pulse.opacity = value
}
}
/**
A property that manages an image for the visualLayer's contents
......
......@@ -32,8 +32,40 @@ import UIKit
@objc(CollectionViewCell)
open class CollectionViewCell: UICollectionViewCell {
/// A reference to the divider.
open internal(set) var divider: Divider!
/// Divider layer.
internal private(set) lazy var divider: Divider = Divider(view: self)
/// Divider color.
@IBInspectable
open var dividerColor: UIColor? {
get {
return divider.color
}
set(value) {
divider.color = value
}
}
/// Divider animation.
open var dividerAlignment: DividerAlignment {
get {
return divider.alignment
}
set(value) {
divider.alignment = value
}
}
/// Divider height.
@IBInspectable
open var dividerHeight: CGFloat {
get {
return divider.height
}
set(value) {
divider.height = value
}
}
/**
A CAShapeLayer used to manage elements that would be affected by
......@@ -44,8 +76,39 @@ open class CollectionViewCell: UICollectionViewCell {
open private(set) lazy var visualLayer = CAShapeLayer()
/// A Pulse reference.
internal private(set) lazy var pulse: Pulse = Pulse()
/// PulseAnimation value.
open var pulseAnimation: PulseAnimation {
get {
return pulse.animation
}
set(value) {
pulse.animation = value
}
}
/// PulseAnimation color.
@IBInspectable
open var pulseColor: UIColor {
get {
return pulse.color
}
set(value) {
pulse.color = value
}
}
/// Pulse opacity.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
open var pulseOpacity: CGFloat {
get {
return pulse.opacity
}
set(value) {
pulse.opacity = value
}
}
/**
A property that manages an image for the visualLayer's contents
......@@ -268,7 +331,6 @@ open class CollectionViewCell: UICollectionViewCell {
open func prepare() {
contentScaleFactor = Device.scale
prepareVisualLayer()
prepareDivider()
}
/// Prepares the visualLayer property.
......@@ -283,9 +345,4 @@ open class CollectionViewCell: UICollectionViewCell {
visualLayer.frame = bounds
visualLayer.cornerRadius = cornerRadius
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
}
......@@ -42,8 +42,8 @@ open class FabButton: Button {
super.prepare()
depthPreset = .depth1
shapePreset = .circle
pulse.animation = .centerWithBacking
pulse.color = Color.white
pulseAnimation = .centerWithBacking
pulseColor = Color.white
tintColor = Color.white
backgroundColor = Color.red.base
}
......
......@@ -40,6 +40,6 @@ open class IconButton: Button {
*/
open override func prepare() {
super.prepare()
pulse.animation = .center
pulseAnimation = .center
}
}
......@@ -39,8 +39,40 @@ public enum NavigationBarStyle: Int {
}
open class NavigationBar: UINavigationBar {
/// A reference to the divider.
open internal(set) var divider: Divider!
/// Divider layer.
internal private(set) lazy var divider: Divider = Divider(view: self)
/// Divider color.
@IBInspectable
open var dividerColor: UIColor? {
get {
return divider.color
}
set(value) {
divider.color = value
}
}
/// Divider animation.
open var dividerAlignment: DividerAlignment {
get {
return divider.alignment
}
set(value) {
divider.alignment = value
}
}
/// Divider height.
@IBInspectable
open var dividerHeight: CGFloat {
get {
return divider.height
}
set(value) {
divider.height = value
}
}
open override var intrinsicContentSize: CGSize {
switch navigationBarStyle {
......@@ -174,9 +206,7 @@ open class NavigationBar: UINavigationBar {
layoutNavigationItem(item: v)
}
if let v = divider {
v.reload()
}
divider.reload()
}
open override func pushItem(_ item: UINavigationItem, animated: Bool) {
......@@ -305,7 +335,6 @@ open class NavigationBar: UINavigationBar {
shadowImage = image
setBackgroundImage(image, for: .default)
backgroundColor = Color.white
prepareDivider()
}
/**
......@@ -327,9 +356,4 @@ open class NavigationBar: UINavigationBar {
}
item.titleView = UIView(frame: .zero)
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
}
......@@ -36,7 +36,7 @@ private var PageTabBarItemKey: UInt8 = 0
open class PageTabBarItem: FlatButton {
open override func prepare() {
super.prepare()
pulse.animation = .none
pulseAnimation = .none
}
}
......
......@@ -30,18 +30,16 @@
import UIKit
open class Pulse {
internal struct Pulse {
/// An Array of layers.
internal lazy var layers = [CAShapeLayer]()
/// A UIColor.
@IBInspectable
open var color = Color.grey.base
internal var color = Color.grey.base
/// A reference to the PulseAnimation.
open var animation = PulseAnimation.pointWithBacking
internal var animation = PulseAnimation.pointWithBacking
/// The opcaity value for the pulse animation.
@IBInspectable
open var opacity: CGFloat = 0.18
internal var opacity: CGFloat = 0.18
}
......@@ -31,9 +31,40 @@
import UIKit
open class PulseView: View {
/// A Pulse reference.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
/// A Pulse reference.
internal private(set) lazy var pulse: Pulse = Pulse()
/// PulseAnimation value.
open var pulseAnimation: PulseAnimation {
get {
return pulse.animation
}
set(value) {
pulse.animation = value
}
}
/// PulseAnimation color.
@IBInspectable
open var pulseColor: UIColor {
get {
return pulse.color
}
set(value) {
pulse.color = value
}
}
/// Pulse opacity.
@IBInspectable
open var pulseOpacity: CGFloat {
get {
return pulse.opacity
}
set(value) {
pulse.opacity = value
}
}
/**
Triggers the pulse animation.
......
......@@ -413,7 +413,7 @@ open class Switch: UIControl {
/// Prepares the button.
private func prepareButton() {
button.pulse.animation = .none
button.pulseAnimation = .none
button.addTarget(self, action: #selector(handleTouchUpInside), for: .touchUpInside)
button.addTarget(self, action: #selector(handleTouchDragInside), for: .touchDragInside)
button.addTarget(self, action: #selector(handleTouchUpOutsideOrCanceled), for: .touchCancel)
......
......@@ -40,8 +40,39 @@ open class TableViewCell: UITableViewCell {
open private(set) lazy var visualLayer = CAShapeLayer()
/// A Pulse reference.
internal private(set) lazy var pulse: Pulse = Pulse()
/// PulseAnimation value.
open var pulseAnimation: PulseAnimation {
get {
return pulse.animation
}
set(value) {
pulse.animation = value
}
}
/// PulseAnimation color.
@IBInspectable
open internal(set) lazy var pulse: Pulse = Pulse()
open var pulseColor: UIColor {
get {
return pulse.color
}
set(value) {
pulse.color = value
}
}
/// Pulse opacity.
@IBInspectable
open var pulseOpacity: CGFloat {
get {
return pulse.opacity
}
set(value) {
pulse.opacity = value
}
}
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
......
......@@ -207,7 +207,7 @@ open class TextField: UITextField {
if nil == clearIconButton {
clearIconButton = IconButton(image: Icon.cm.clear, tintColor: placeholderColor)
clearIconButton!.contentEdgeInsets = .zero
clearIconButton!.pulse.animation = .center
clearIconButton!.pulseAnimation = .center
clearButtonMode = .never
rightViewMode = .whileEditing
rightView = clearIconButton
......@@ -242,7 +242,7 @@ open class TextField: UITextField {
if nil == visibilityIconButton {
visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54))
visibilityIconButton!.contentEdgeInsets = .zero
visibilityIconButton!.pulse.animation = .center
visibilityIconButton!.pulseAnimation = .center
isSecureTextEntry = true
clearButtonMode = .never
rightViewMode = .whileEditing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment