home-assistant / Iconic

:art: Auto-generated icon font library for iOS, watchOS and tvOS
Apache License 2.0
1.58k stars 87 forks source link

Provide a more Swifty template #2

Closed AliSoftware closed 8 years ago

AliSoftware commented 8 years ago

Given that Iconic is based on SwiftGen, it's easy to provide more than one template for the user to choose from.


Template suggestion

// Swift-only template

// Create IconicFont Mixin. Because Mixins are awesome.
public protocol IconicFont {
    public static func register()
    public static func font(fontSize: CGFloat) -> UIFont!
    public func attributedString(size: CGFloat, color: UIColor?) -> NSAttributedString!
    public func image(size: CGFloat, color: UIColor?) -> UIImage!
    public func unicodeString() -> String!
}

public extension IconicFont {
  … implementation goes here …
}

public enum FontAwesomeIcon: IconicFont {
  case Adjust
  case Adn
  case AlignCenter
  …
  // and it will get the IconicFont default implementations for free!
}

Usage

FontAwesomeIcon.register()
let font: UIFont = FontAwesomeIcon.font(size: 14)
let img: UIImage = FontAwesomeIcon.AlignCenter.image(size: 100, color: nil)

let icon = FontAwesomeIcon.AlignCenter
imageView.image = icon.image(size: imageView.bounds.size)
label.attributedText = icon.attributedString(size: 14)
dzenbot commented 8 years ago

Great idea! Will def. try that out. I'm worried about having fragmented XP. If this happens, I think I would need to default to the swifty template I think.