Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support iconTintColor #274

Merged
merged 5 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
Master
------

v3.5.0
-----

* Added support for template images. [#274](https://github.com/Skyscanner/SkyFloatingLabelTextField/pull/274).

v3.6.0
------

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions Sources/SkyFloatingLabelTextFieldWithIcon.swift
Expand Up @@ -56,6 +56,18 @@ open class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
}
}

/// A Bool value that determines if the UIImage should be templated or not
@IBInspectable
dynamic open var templateImage: Bool = true {
didSet {
if templateImage {
let templatedOriginalImage = self.iconImageView.image?
.withRenderingMode(.alwaysTemplate)
self.iconImageView.image = templatedOriginalImage
}
}
}

/// A UILabel value that identifies the label used to display the icon
open var iconLabel: UILabel!

Expand All @@ -80,7 +92,12 @@ open class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
@IBInspectable
dynamic open var iconColor: UIColor = UIColor.gray {
didSet {
updateIconLabelColor()
if self.iconType == .font {
updateIconLabelColor()
}
if self.iconType == .image && self.templateImage {
updateImageViewTintColor()
}
}
}

Expand Down Expand Up @@ -196,6 +213,7 @@ open class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
iconImageView.contentMode = .scaleAspectFit
iconImageView.autoresizingMask = [.flexibleTopMargin, .flexibleRightMargin]
self.iconImageView = iconImageView
self.templateImage = true
addSubview(iconImageView)
}

Expand All @@ -218,7 +236,22 @@ open class SkyFloatingLabelTextFieldWithIcon: SkyFloatingLabelTextField {
/// Update the colors for the control. Override to customize colors.
override open func updateColors() {
super.updateColors()
updateIconLabelColor()
if self.iconType == .font {
updateIconLabelColor()
}
if self.iconType == .image && self.templateImage {
updateImageViewTintColor()
}
}

fileprivate func updateImageViewTintColor() {
if !isEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be done if templateImage is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change added. Although not doing so has no side effects

iconImageView.tintColor = disabledColor
} else if hasErrorMessage {
iconImageView.tintColor = errorColor
} else {
iconImageView.tintColor = editingOrSelected ? selectedIconColor : iconColor
}
}

fileprivate func updateIconLabelColor() {
Expand Down