From 286e4103603c95e2084e527e7d4f5c4260aa4d6e Mon Sep 17 00:00:00 2001 From: cemolcay Date: Sat, 13 Feb 2016 18:41:18 -0800 Subject: [PATCH] [TVOSButton] style changes and content changes logic --- TVOSButton/TVOSButton.swift | 41 ++++++++++--------- .../TVOSButtonExample/ViewController.swift | 1 - 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/TVOSButton/TVOSButton.swift b/TVOSButton/TVOSButton.swift index 42a65ea..84df39a 100644 --- a/TVOSButton/TVOSButton.swift +++ b/TVOSButton/TVOSButton.swift @@ -62,12 +62,14 @@ public struct TVOSButtonStyle { button.tvosButtonBackgroundImageView.image = backgroundImage button.tvosButton.layer.cornerRadius = cornerRadius ?? 0 button.tvosButton.transform = CGAffineTransformMakeScale(scale ?? 1, scale ?? 1) + // shadow if let shadow = shadow { shadow.applyStyle(onLayer: button.tvosButton.layer) } else { TVOSButtonShadow.resetStyle(onLayer: button.tvosButton.layer) } + // content view if let contentView = contentView { button.tvosCustomContentView.addSubview(contentView) @@ -76,21 +78,29 @@ public struct TVOSButtonStyle { subview.removeFromSuperview() } } + // badge if let badge = badgeStyle { badge.applyStyle(onImageView: button.tvosBadge) + button.tvosBadge.image = button.badgeImage } else { TVOSButtonImage.resetStyle(onImageView: button.tvosBadge) + button.tvosBadge.image = nil } + // text if let text = textStyle { text.applyStyle(onLabel: button.tvosTextLabel) + button.tvosTextLabel.text = button.textLabelText } else { TVOSButtonLabel.resetStyle(onLabel: button.tvosTextLabel) + button.tvosTextLabel.text = nil } + // title if let title = titleStyle { title.applyStyle(onLabel: button.tvosTitleLabel) + button.tvosTitleLabel.text = button.titleLabelText } else { TVOSButtonLabel.resetStyle(onLabel: button.tvosTitleLabel) } @@ -140,23 +150,9 @@ public class TVOSButton: UIButton { // MARK: Public Properties - public var textLabelText: String? { - didSet { - tvosTextLabel.text = textLabelText - } - } - - public var titleLabelText: String? { - didSet { - tvosTitleLabel.text = titleLabelText - } - } - - public var badgeImage: UIImage? { - didSet { - tvosBadge.image = badgeImage - } - } + public var textLabelText: String? + public var titleLabelText: String? + public var badgeImage: UIImage? public override var enabled: Bool { didSet { @@ -219,7 +215,14 @@ public class TVOSButton: UIButton { // add title constraints tvosTitleLabel.fillHorizontal(toView: self) tvosTitleLabel.pinHeight(50) - tvosTitleLabelTopConstraint = NSLayoutConstraint(item: tvosTitleLabel, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1, constant: 0) + tvosTitleLabelTopConstraint = NSLayoutConstraint( + item: tvosTitleLabel, + attribute: .Top, + relatedBy: .Equal, + toItem: self, + attribute: .Bottom, + multiplier: 1, + constant: 0) addConstraint(tvosTitleLabelTopConstraint) // finalize layer.masksToBounds = false @@ -254,7 +257,7 @@ public class TVOSButton: UIButton { delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, - options: UIViewAnimationOptions.AllowAnimatedContent, + options: .AllowAnimatedContent, animations: { self.tvosTitleLabelTopConstraint.constant = self.tvosButtonState == .Focused ? 20 : 0 style.applyStyle(onButton: self) diff --git a/TVOSButtonExample/TVOSButtonExample/ViewController.swift b/TVOSButtonExample/TVOSButtonExample/ViewController.swift index 4952ca7..4d892a3 100644 --- a/TVOSButtonExample/TVOSButtonExample/ViewController.swift +++ b/TVOSButtonExample/TVOSButtonExample/ViewController.swift @@ -58,7 +58,6 @@ class ExampleButton: TVOSButton { } } - class ViewController: UIViewController { @IBOutlet var button: ExampleButton!