Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Minor odds and ends
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed May 16, 2019
1 parent de2aa7f commit 662ba75
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Iconic.podspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@version = '1.5.1'
@version = '1.4'

Pod::Spec.new do |s|

Expand Down
84 changes: 41 additions & 43 deletions Source/IconImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,51 @@
import UIKit

#if os(iOS) || os(tvOS)

/** An Image View subclass, capable of rendering icons. Only supported for iOS and tvOS. */
public class IconImageView: UIImageView {

// MARK: - Public Variables

/** The icon drawable to be used as image. */
public var iconDrawable: IconDrawable? {
didSet {
updateIconImage()
}
}

// MARK: - Overrides

public override var frame: CGRect {
didSet {
updateIconImage()
}
/** An Image View subclass, capable of rendering icons. Only supported for iOS and tvOS. */
public class IconImageView: UIImageView {

// MARK: - Public Variables

/** The icon drawable to be used as image. */
public var iconDrawable: IconDrawable? {
didSet {
updateIconImage()
}

public override func layoutSubviews() {
super.layoutSubviews()

}

// MARK: - Overrides

public override var frame: CGRect {
didSet {
updateIconImage()
}

// MARK: - Image Constructor

/**
Updates the icon image, only when the frame is not empty.
*/
fileprivate func updateIconImage() {

// No need to update the icon with empty frame
if frame.isEmpty {
return
}

if let icon = iconDrawable {
let image = icon.image(ofSize: frame.size, color: nil)
self.image = image.withRenderingMode(.alwaysTemplate)
} else {
self.image = nil
}
}

public override func layoutSubviews() {
super.layoutSubviews()

updateIconImage()
}

// MARK: - Image Constructor

/**
Updates the icon image, only when the frame is not empty.
*/
fileprivate func updateIconImage() {

// No need to update the icon with empty frame
if frame.isEmpty {
return
}

if let icon = iconDrawable {
let image = icon.image(ofSize: frame.size, color: nil)
self.image = image.withRenderingMode(.alwaysTemplate)
} else {
self.image = nil
}
}
}
#endif

8 changes: 0 additions & 8 deletions Source/iconic-default.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import UIKit
return {{enumName}}.familyName as NSString
}

/** The icon font's total count of available icons. */
class var {{enumName|lowerFirstWord}}Count: Int {
return {{enumName}}.count
}

/**
Returns the icon font object for the specified size.

Expand Down Expand Up @@ -169,9 +164,6 @@ public final class {{enumName}}View: IconImageView {
{% for icon in icons %}
case {{icon.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord}}Icon
{% endfor %}

/** The icon font's total count of available icons. */
public static var count: Int { return {{ icons.count }} }
}

extension {{enumName}} : IconDrawable {
Expand Down

0 comments on commit 662ba75

Please sign in to comment.