Skip to content

Commit

Permalink
[TVOSButton] style changes and content changes logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cemolcay committed Feb 14, 2016
1 parent 82c5a00 commit 286e410
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
41 changes: 22 additions & 19 deletions TVOSButton/TVOSButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion TVOSButtonExample/TVOSButtonExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class ExampleButton: TVOSButton {
}
}


class ViewController: UIViewController {

@IBOutlet var button: ExampleButton!
Expand Down

0 comments on commit 286e410

Please sign in to comment.