Skip to content

Commit 00ef111

Browse files
Merge pull request #1 from mallman/label_symbol
Add an extension to bring SFSymbols to the SwiftUI Label
2 parents adf3c68 + f8c193b commit 00ef111

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import SwiftUI
2+
3+
@available(iOS 14.0, *)
4+
public extension Label {
5+
init(_ titleKey: LocalizedStringKey, symbol: SFSymbol) where Title == Text, Icon == Image {
6+
switch symbol {
7+
case .custom(let name):
8+
self = Label(titleKey, image: name)
9+
default:
10+
self = Label(titleKey, systemImage: symbol.name)
11+
}
12+
}
13+
14+
init<S>(_ title: S, symbol: SFSymbol) where S: StringProtocol, Title == Text, Icon == Image {
15+
switch symbol {
16+
case .custom(let name):
17+
self = Label(title, image: name)
18+
default:
19+
self = Label(title, systemImage: symbol.name)
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)