forked from home-assistant/Iconic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconic-default.stencil
157 lines (128 loc) · 5.95 KB
/
iconic-default.stencil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen
import UIKit
{% if icons %}
extension Iconic {
/**
Registers the {{familyName}} font to Iconic.
You shall do this once, when launching your application. Internally, the icon mapping is retrieved and
kept in memory during the application's life term.
*/
public class func register{{enumName}}() {
Iconic.registerFont("{{familyName}}", map: {{enumName}}Map)
}
/**
Returns the {{familyName}} font object in the specified size.
- parameter fontSize: The size (in points) to which the font is scaled.
This value must be greater than 0.0, or a system Font object will be returned.
*/
public class func {{enumName|lowerFirstWord}}FontOfSize(fontSize: CGFloat) -> UIFont? {
return Iconic.iconFontOfSize(fontSize)
}
/**
Creates an attributed string with the specified icon enum type, with optional color.
- parameter icon: The icon enum type.
- parameter size: The size of the text, in points.
- parameter color: Optional color to be applied to the icon.
*/
public class func attributedStringFor{{enumName}}(icon: {{enumName}}, size: CGFloat, color: UIColor?) -> NSAttributedString? {
return Iconic.attributedStringForIndex(icon.rawValue, size: size, color: color)
}
/**
Creates an attributed string with the specified icon enum type, with optional color and alignment.
The optional alinment can be really helpful when appending an icon to another attributed string with different fonts.
It may also help for adjusting the icon's baseline, when using either top and bottom insets.
- parameter icon: The icon enum type.
- parameter size: The size of the text, in points.
- parameter color: Optional color to be applied to the icon.
- parameter edgeInsets: Optional edge insets to be used as horizontal and vertical margins.
*/
public class func attributedStringFor{{enumName}}(icon: {{enumName}}, size: CGFloat, color: UIColor?, edgeInsets: UIEdgeInsets) -> NSAttributedString? {
return Iconic.attributedStringForIndex(icon.rawValue, size: size, color: color, edgeInsets: edgeInsets)
}
/**
Creates an image out of an attributed string with the specified icon enum type.
- parameter icon: The icon enum type.
- parameter size: The size of the text, in points.
- parameter color: Optional color to be applied to the icon.
*/
public class func imageFor{{enumName}}(icon: {{enumName}}, size: CGFloat, color: UIColor?) -> UIImage? {
return Iconic.imageForIndex(icon.rawValue, size: size, color: color)
}
/**
Returns a string representation of an unicode for the specified icon enum type.
- parameter icon: The icon enum type.
- returns An unicode string representation.
*/
public class func unicodeStringFor{{enumName}}(icon: {{enumName}}) -> String? {
return Iconic.unicodeStringForIndex(icon.rawValue)
}
}
extension UIBarButtonItem {
/**
Initializes a new item using the specified icon enum type and other properties.
- parameter {{enumName|lowerFirstWord}}: The icon enum type to be used as image.
- parameter size: The size of the image, in points.
- parameter target: The object that receives the action message.
- parameter action: The action to send to target when this item is selected.
*/
public convenience init({{enumName|lowerFirstWord}}: {{enumName}}, size: CGFloat, target: AnyObject?, action: Selector) {
let image = Iconic.imageForIndex({{enumName|lowerFirstWord}}.rawValue, size: size, color: .blackColor())
self.init(image: image, style: .Plain, target: target, action: action)
}
}
extension UITabBarItem {
/**
Initializes a new item using the specified icon enum type and other properties.
- parameter {{enumName|lowerFirstWord}}: The icon enum type to be used as image.
- parameter size: The size of the image, in points.
- parameter title: The item's title. If nil, a title is not displayed.
- parameter tag: The receiver's tag, an integer that you can use to identify bar item objects in your application.
*/
public convenience init({{enumName|lowerFirstWord}}: {{enumName}}, size: CGFloat, title: String?, tag: Int) {
let image = Iconic.imageForIndex({{enumName|lowerFirstWord}}.rawValue, size: size, color: .blackColor())
self.init(title: title, image: image, tag: tag)
}
}
extension UIButton {
/**
Sets the icon to use for the specified state.
- parameter {{enumName|lowerFirstWord}}: The icon enum type to be used as image.
- parameter size: The size of the image, in points.
- parameter state: The state that uses the specified title. The values are described in UIControlState.
*/
public func set{{enumName}}({{enumName|lowerFirstWord}}: {{enumName}}, size: CGFloat, forState: UIControlState) {
self.setIconForIndex({{enumName|lowerFirstWord}}.rawValue, size: size, forState: state)
}
}
/**
A strongly typed representation of every available icon name.
*/
@objc public enum {{enumName}}: Int {
{% for icon in icons %}
case {{icon.name|swiftIdentifier|snakeToCamelCase}}
{% endfor %}
// Useful to get the total count of icons. This index doesn't have any associated unicode value.
case TotalCount
}
/**
A list of unicode characters associated with each {{enumName}} case, in order.
*/
public let {{enumName}}Map: Array<String> = [
{% for icon in icons %}
"{{icon.unicode|unicodeCase}}",
{% endfor %}
]
/**
Returns the name of an icon enum type as a string.
*/
public func NSStringFrom{{enumName}}({{enumName|lowercase}}: {{enumName}}) -> String {
switch {{enumName|lowercase}} {
{% for icon in icons %}
case .{{icon.name|swiftIdentifier|snakeToCamelCase}}: return "{{icon.name|swiftIdentifier|snakeToCamelCase}}"
{% endfor %}
default: return ""
}
}
{% else %}
// No icon found
{% endif %}