Swift库的字体图标
请★这个图书馆。
现在,您不必下载不同的库即可包括不同的字体图标。此SwiftIcons库可帮助您使用以下任何字体图标中的图标。
SwiftIcons支持对象库中的不同对象。
- uiimage
- UIImageView
- Uilabel
- Uibutton
- uisegedcontrol
- Uitabbaritem
- Uislider
- Uibarbuttonitem
- UiviewController
- uitextfield
- uistepper
要求
- iOS 9.0+
- XCode 8
安装
可可录
Cocoapods是可可项目的依赖性经理。
确保您通过运行具有最新版本的可可录。
$ gem install cocoapods
# (or if the above fails)
$ sudo gem install cocoapods
通过运行来更新您的本地规格存储库:
$ pod repo update
将以下几行添加到您的Podfile :
SwiftIcons\’, \’~> 3.0\’
end\”>
target \'YourProject\' do use_frameworks! pod \' SwiftIcons \' , \'~> 3.0\' end
然后运行以下命令
$ pod install
您可以通过将图书馆导入到任何需要的地方来开始使用库
import SwiftIcons
迦太基
迦太基是可可项目的分散依赖经理。
安装最新版本的迦太基。
将此线添加到您的Cartfile :
github \"ranesr/ SwiftIcons \" ~> 3.0
或用于master
github \"ranesr/ SwiftIcons \" \"master\"
然后运行carthage update --platform ios ,并通过遵循迦太基的这些说明将构建框架添加到您的项目中。
手动
从Source文件夹复制所有文件。链接到文件。
- SwiftIcons .Swift
- dtf
- emoji.ttf
- fontawesomebrands.ttf
- fontawesomeregular.ttf
- fontawesomesolid.ttf
- icofont.ttf
- ionicons.ttf
- Linearicons.ttf
- Mapicons.ttf
- 材料
- openiconic.ttf
- stateface.ttf
- Weathericons.ttf
- typicons.ttf
检查要导入项目中的所有TTF文件,“项目”>“目标”>“复制捆绑资源”
库参考
您可以在此处查看库参考文献文档。
用法
- 不再有图像图标
每个字体图标都有不同的字体类型
| 字体图标 | 版本 | 字体类型 | 图标 |
|---|---|---|---|
| 滴管 | 2.0 | 滴管 | 滴管 |
| 表情符号 | 表情符号 | 表情符号 | |
| fontawesome | 5.1.0 | fontawesome | fontawesome |
| ICOFONT | 1.0.0 beta | ICOFONT | ICOFONT |
| 离子 | 2.0.1 | 离子 | 离子 |
| 线性化 | 1.0.0 | 线性化 | 线性化 |
| 地图 – 元音 | 3.0.2 | Mapicons | Mapicons |
| 物质图标 | 2.2.0 | GooglematerialldSign | GooglematerialldSign |
| 开放标志性 | 1.1.1 | 开言 | 开言 |
| 状态面图标 | 状态 | 状态 | |
| 天气图标 | 2.0.10 | 天气 | 天气 |
| 古使 | 2.0.7 | 古使 | 古使 |
将图标设置为任何对象时,您必须提及它是哪种字体类型,然后选择要从该特定字体图标设置的图标。
uiimage
SwiftIcons
UIImage.init(icon: .emoji(.airplane), size: CGSize(width: 35, height: 35))
// Icon with colors
UIImage.init(icon: .emoji(.airplane), size: CGSize(width: 35, height: 35), textColor: .red)
UIImage.init(icon: .emoji(.airplane), size: CGSize(width: 35, height: 35), textColor: .white, backgroundColor: .red)
// Stacked icons with bigger background
UIImage.init(bgIcon: .fontAwesomeRegular(.circle), topIcon: .fontAwesomeRegular(.square))
// Stacked icons with smaller background
UIImage.init(bgIcon: .fontAwesomeSolid(.camera), topIcon: .fontAwesomeSolid(.ban), topTextColor: .red, bgLarge: false)
// Stacked icons with custom size
UIImage.init(bgIcon: .fontAwesomeSolid(.camera), topIcon: .fontAwesomeSolid(.ban), topTextColor: .red, bgLarge: false, size: CGSize(width: 50, height: 50))
\”>
import SwiftIcons UIImage . init ( icon : . emoji ( . airplane ) , size : CGSize ( width : 35 , height : 35 ) ) // Icon with colors UIImage . init ( icon : . emoji ( . airplane ) , size : CGSize ( width : 35 , height : 35 ) , textColor : . red ) UIImage . init ( icon : . emoji ( . airplane ) , size : CGSize ( width : 35 , height : 35 ) , textColor : . white , backgroundColor : . red ) // Stacked icons with bigger background UIImage . init ( bgIcon : . fontAwesomeRegular ( . circle ) , topIcon : . fontAwesomeRegular ( . square ) ) // Stacked icons with smaller background UIImage . init ( bgIcon : . fontAwesomeSolid ( . camera ) , topIcon : . fontAwesomeSolid ( . ban ) , topTextColor : . red , bgLarge : false ) // Stacked icons with custom size UIImage . init ( bgIcon : . fontAwesomeSolid ( . camera ) , topIcon : . fontAwesomeSolid ( . ban ) , topTextColor : . red , bgLarge : false , size : CGSize ( width : 50 , height : 50 ) )
UIImageView
SwiftIcons
// Setting icon to image view
imageView.setIcon(icon: .weather(.rainMix))
// Icon with colors
imageView.setIcon(icon: .mapicons(.amusementPark), textColor: .white, backgroundColor: .blue, size: nil)
\”>
import SwiftIcons // Setting icon to image view imageView . setIcon ( icon : . weather ( . rainMix ) ) // Icon with colors imageView . setIcon ( icon : . mapicons ( . amusementPark ) , textColor : . white , backgroundColor : . blue , size : nil )
Uilabel
SwiftIcons
// Setting icon to label
label.setIcon(icon: .ionicons(.paintbrush), iconSize: 70)
// Icon with colors
label.setIcon(icon: .googleMaterialDesign(.rowing), iconSize: 70, color: .white, bgColor: textColor)
// Icon with text around it
label.setIcon(prefixText: "Bus ", icon: .linearIcons(.bus), postfixText: " icon", size: 20)
// Icon with color & colored text around it
label.setIcon(prefixText: "Medal ", prefixTextColor: .red, icon: .ionicons(.ribbonA), iconColor: .red, postfixText: "", postfixTextColor: .red, size: nil, iconSize: 40)
// Icon with text with different fonts around it
label.setIcon(prefixText: "Font ", prefixTextFont: font1!, icon: .fontAwesomeSolid(.font), postfixText: " icon", postfixTextFont: font2!)
// Icon with text with different fonts & colors around it
label.setIcon(prefixText: "Bike ", prefixTextFont: font1!, prefixTextColor: .red, icon: .mapicons(.bicycling), iconColor: textColor, postfixText: " icon", postfixTextFont: font2!, postfixTextColor: .blue, iconSize: 30)
\”>
import SwiftIcons // Setting icon to label label . setIcon ( icon : . ionicons ( . paintbrush ) , iconSize : 70 ) // Icon with colors label . setIcon ( icon : . googleMaterialDesign ( . rowing ) , iconSize : 70 , color : . white , bgColor : textColor ) // Icon with text around it label . setIcon ( prefixText : \" Bus \" , icon : . linearIcons ( . bus ) , postfixText : \" icon \" , size : 20 ) // Icon with color & colored text around it label . setIcon ( prefixText : \" Medal \" , prefixTextColor : . red , icon : . ionicons ( . ribbonA ) , iconColor : . red , postfixText : \" \" , postfixTextColor : . red , size : nil , iconSize : 40 ) // Icon with text with different fonts around it label . setIcon ( prefixText : \" Font \" , prefixTextFont : font1! , icon : . fontAwesomeSolid ( . font ) , postfixText : \" icon \" , postfixTextFont : font2! ) // Icon with text with different fonts & colors around it label . setIcon ( prefixText : \" Bike \" , prefixTextFont : font1! , prefixTextColor : . red , icon : . mapicons ( . bicycling ) , iconColor : textColor , postfixText : \" icon \" , postfixTextFont : font2! , postfixTextColor : . blue , iconSize : 30 )
Uibutton
SwiftIcons
// Setting icon to button
button.setIcon(icon: .linearIcons(.phone), forState: .normal)
// Icon with size and color
button.setIcon(icon: .openIconic(.clipboard), iconSize: 70, color: .blue, forState: .normal)
// Icon with text around it
button.setIcon(prefixText: "Please ", icon: .googleMaterialDesign(.print), postfixText: " print", forState: .normal)
// Icon with color & colored text around it
button.setIcon(prefixText: "Lock ", prefixTextColor: .red, icon: .googleMaterialDesign(.lock), iconColor: .yellow, postfixText: " icon", postfixTextColor: .blue, forState: .normal, textSize: 15, iconSize: 20)
// Icon with text with different fonts around it
button.setIcon(prefixText: "Happy ", prefixTextFont: font1!, icon: .ionicons(.happy), postfixText: " face", postfixTextFont: font2!, forState: .normal)
// Icon with text with different fonts & colors around it
button.setIcon(prefixText: "Pulse ", prefixTextFont: font1!, prefixTextColor: .darkGray, icon: .openIconic(.pulse), iconColor: .red, postfixText: " icon", postfixTextFont: font2!, postfixTextColor: .purple, forState: .normal, iconSize: 40)
// Icon with title below icon
button.setIcon(icon: .emoji(.ferrisWheel), title: "Ferris Wheel", color: .red, forState: .normal)
// Icon with title below icon with different color & custom font
button.setIcon(icon: .weather(.rainMix), iconColor: .yellow, title: "RAIN MIX", titleColor: .red, font: font!, backgroundColor: .clear, borderSize: 1, borderColor: .green, forState: .normal)
\”>
import SwiftIcons // Setting icon to button button . setIcon ( icon : . linearIcons ( . phone ) , forState : . normal ) // Icon with size and color button . setIcon ( icon : . openIconic ( . clipboard ) , iconSize : 70 , color : . blue , forState : . normal ) // Icon with text around it button . setIcon ( prefixText : \" Please \" , icon : . googleMaterialDesign ( . print ) , postfixText : \" print \" , forState : . normal ) // Icon with color & colored text around it button . setIcon ( prefixText : \" Lock \" , prefixTextColor : . red , icon : . googleMaterialDesign ( . lock ) , iconColor : . yellow , postfixText : \" icon \" , postfixTextColor : . blue , forState : . normal , textSize : 15 , iconSize : 20 ) // Icon with text with different fonts around it button . setIcon ( prefixText : \" Happy \" , prefixTextFont : font1! , icon : . ionicons ( . happy ) , postfixText : \" face \" , postfixTextFont : font2! , forState : . normal ) // Icon with text with different fonts & colors around it button . setIcon ( prefixText : \" Pulse \" , prefixTextFont : font1! , prefixTextColor : . darkGray , icon : . openIconic ( . pulse ) , iconColor : . red , postfixText : \" icon \" , postfixTextFont : font2! , postfixTextColor : . purple , forState : . normal , iconSize : 40 ) // Icon with title below icon button . setIcon ( icon : . emoji ( . ferrisWheel ) , title : \" Ferris Wheel \" , color : . red , forState : . normal ) // Icon with title below icon with different color & custom font button . setIcon ( icon : . weather ( . rainMix ) , iconColor : . yellow , title : \" RAIN MIX \" , titleColor : . red , font : font! , backgroundColor : . clear , borderSize : 1 , borderColor : . green , forState : . normal )
uisegedcontrol
SwiftIcons
// Setting icon at particular index
segmentedControl.setIcon(icon: .linearIcons(.thumbsUp), forSegmentAtIndex: 0)
segmentedControl.setIcon(icon: .linearIcons(.thumbsDown), forSegmentAtIndex: 1)
// Icons with sizes & colors
segmentedControl.setIcon(icon: .fontAwesomeSolid(.male), color: .red, iconSize: 50, forSegmentAtIndex: 0)
segmentedControl.setIcon(icon: .fontAwesomeSolid(.female), color: .purple, iconSize: 50, forSegmentAtIndex: 1)
\”>
import SwiftIcons // Setting icon at particular index segmentedControl . setIcon ( icon : . linearIcons ( . thumbsUp ) , forSegmentAtIndex : 0 ) segmentedControl . setIcon ( icon : . linearIcons ( . thumbsDown ) , forSegmentAtIndex : 1 ) // Icons with sizes & colors segmentedControl . setIcon ( icon : . fontAwesomeSolid ( . male ) , color : . red , iconSize : 50 , forSegmentAtIndex : 0 ) segmentedControl . setIcon ( icon : . fontAwesomeSolid ( . female ) , color : . purple , iconSize : 50 , forSegmentAtIndex : 1 )
Uitabbaritem
SwiftIcons
// Setting icon to tab bar item
tabBar.items?[0].setIcon(icon: .fontAwesomeSolid(.font), size: nil, textColor: .lightGray)
// Stacked icons for tab bar item
tabBar.items?[1].setIcon(bgIcon: .fontAwesomeRegular(.circle), bgTextColor: .lightGray, topIcon: .fontAwesomeSolid(.square), topTextColor: .lightGray, bgLarge: true, size: nil)
\”>
import SwiftIcons // Setting icon to tab bar item tabBar . items ? [ 0 ] . setIcon ( icon : . fontAwesomeSolid ( . font ) , size : nil , textColor : . lightGray ) // Stacked icons for tab bar item tabBar . items ? [ 1 ] . setIcon ( bgIcon : . fontAwesomeRegular ( . circle ) , bgTextColor : . lightGray , topIcon : . fontAwesomeSolid ( . square ) , topTextColor : . lightGray , bgLarge : true , size : nil )
Uislider
SwiftIcons
// Change minimum & maximum value icons
slider.setMaximumValueIcon(icon: .emoji(.digitNine))
slider.setMinimumValueIcon(icon: .emoji(.digitZero))
// Change minimum & maximum value icons with colors
slider.setMaximumValueIcon(icon: .linearIcons(.pointerUp), customSize: nil, textColor: .red, backgroundColor: .clear)
slider.setMinimumValueIcon(icon: .linearIcons(.pointerDown), customSize: nil, textColor: .blue, backgroundColor: .clear)
\”>
import SwiftIcons // Change minimum & maximum value icons slider . setMaximumValueIcon ( icon : . emoji ( . digitNine ) ) slider . setMinimumValueIcon ( icon : . emoji ( . digitZero ) ) // Change minimum & maximum value icons with colors slider . setMaximumValueIcon ( icon : . linearIcons ( . pointerUp ) , customSize : nil , textColor : . red , backgroundColor : . clear ) slider . setMinimumValueIcon ( icon : . linearIcons ( . pointerDown ) , customSize : nil , textColor : . blue , backgroundColor : . clear )
Uibarbuttonitem
SwiftIcons
// Setting icon to bar button item
barButtonItem.setIcon(icon: .ionicons(.iosFootball), iconSize: 30)
// Icon with colors
barButtonItem.setIcon(icon: .ionicons(.iosFootball), iconSize: 30, color: textColor)
// Icon with custom cgRect
barButtonItem.setIcon(icon: .ionicons(.iosFootball), iconSize: 30, color: textColor, cgRect: CGRect(x: 0, y: 0, width: 30, height: 30), target: self, action: #selector(barButtonItem(sender:)))
// Icon with text around it
barButtonItem.setIcon(prefixText: "Please ", icon: .ionicons(.iosDownload), postfixText: " download", cgRect: CGRect(x: 0, y: 0, width: 30, height: 30), size: 23, target: self, action: #selector(barButtonItem(sender:)))
// Icon with color & colored text around it
barButtonItem.setIcon(prefixText: "Blue ", prefixTextColor: .red, icon: .ionicons(.iosFootball), iconColor: .blue, postfixText: " football", postfixTextColor: .green, cgRect: CGRect(x: 0, y: 0, width: 30, height: 30), size: 20, iconSize: 30, target: self, action: #selector(barButtonItem(sender:)))
// Icon with text with different fonts around it
barButtonItem.setIcon(prefixText: "Digit ", prefixTextFont: font1!, icon: .emoji(.digitOne), postfixText: " One", postfixTextFont: font2!, cgRect: CGRect(x: 0, y: 0, width: 30, height: 30), target: self, action: #selector(barButtonItem(sender:)))
// Icon with text with different fonts & colors around it
barButtonItem.setIcon(prefixText: "", prefixTextFont: font1!, prefixTextColor: .red, icon: .ionicons(.iosFootball), iconColor: .blue, postfixText: " football", postfixTextFont: font2!, postfixTextColor: .green, cgRect: CGRect(x: 0, y: 0, width: 30, height: 30), iconSize: 24, target: self, action: #selector(barButtonItem(sender:)))
\”>
import SwiftIcons // Setting icon to bar button item barButtonItem . setIcon ( icon : . ionicons ( . iosFootball ) , iconSize : 30 ) // Icon with colors barButtonItem . setIcon ( icon : . ionicons ( . iosFootball ) , iconSize : 30 , color : textColor ) // Icon with custom cgRect barButtonItem . setIcon ( icon : . ionicons ( . iosFootball ) , iconSize : 30 , color : textColor , cgRect : CGRect ( x : 0 , y : 0 , width : 30 , height : 30 ) , target : self , action : #selector ( barButtonItem ( sender : ) ) ) // Icon with text around it barButtonItem . setIcon ( prefixText : \" Please \" , icon : . ionicons ( . iosDownload ) , postfixText : \" download \" , cgRect : CGRect ( x : 0 , y : 0 , width : 30 , height : 30 ) , size : 23 , target : self , action : #selector ( barButtonItem ( sender : ) ) ) // Icon with color & colored text around it barButtonItem . setIcon ( prefixText : \" Blue \" , prefixTextColor : . red , icon : . ionicons ( . iosFootball ) , iconColor : . blue , postfixText : \" football \" , postfixTextColor : . green , cgRect : CGRect ( x : 0 , y : 0 , width : 30 , height : 30 ) , size : 20 , iconSize : 30 , target : self , action : #selector ( barButtonItem ( sender : ) ) ) // Icon with text with different fonts around it barButtonItem . setIcon ( prefixText : \" Digit \" , prefixTextFont : font1! , icon : . emoji ( . digitOne ) , postfixText : \" One \" , postfixTextFont : font2! , cgRect : CGRect ( x : 0 , y : 0 , width : 30 , height : 30 ) , target : self , action : #selector ( barButtonItem ( sender : ) ) ) // Icon with text with different fonts & colors around it barButtonItem . setIcon ( prefixText : \" \" , prefixTextFont : font1! , prefixTextColor : . red , icon : . ionicons ( . iosFootball ) , iconColor : . blue , postfixText : \" football \" , postfixTextFont : font2! , postfixTextColor : . green , cgRect : CGRect ( x : 0 , y : 0 , width : 30 , height : 30 ) , iconSize : 24 , target : self , action : #selector ( barButtonItem ( sender : ) ) )
UiviewController
SwiftIcons
// Setting icon to the title
self.setTitleIcon(icon: .emoji(.animalHorse), iconSize: 30, color: .red)
\”>
import SwiftIcons // Setting icon to the title self . setTitleIcon ( icon : . emoji ( . animalHorse ) , iconSize : 30 , color : . red )
uitextfield
SwiftIcons
// Setting left view icon
textfield.setLeftViewIcon(icon: .fontAwesomeSolid(.search))
// Left view icon with colors & leftViewMode
textfield.setLeftViewIcon(icon: .state(.TX), leftViewMode: .always, textColor: .blue, backgroundColor: .clear, size: nil)
textfield.setLeftViewIcon(icon: .googleMaterialDesign(.plusOne), leftViewMode: .unlessEditing, textColor: .green, backgroundColor: .clear, size: nil)
// Setting right view icon
textfield.setRightViewIcon(icon: .openIconic(.questionMark))
// Right view icon with colors & rightViewMode
textfield.setRightViewIcon(icon: .weather(.rainMix), rightViewMode: .always, textColor: .red, backgroundColor: .clear, size: nil)
\”>
import SwiftIcons // Setting left view icon textfield . setLeftViewIcon ( icon : . fontAwesomeSolid ( . search ) ) // Left view icon with colors & leftViewMode textfield . setLeftViewIcon ( icon : . state ( . TX ) , leftViewMode : . always , textColor : . blue , backgroundColor : . clear , size : nil ) textfield . setLeftViewIcon ( icon : . googleMaterialDesign ( . plusOne ) , leftViewMode : . unlessEditing , textColor : . green , backgroundColor : . clear , size : nil ) // Setting right view icon textfield . setRightViewIcon ( icon : . openIconic ( . questionMark ) ) // Right view icon with colors & rightViewMode textfield . setRightViewIcon ( icon : . weather ( . rainMix ) , rightViewMode : . always , textColor : . red , backgroundColor : . clear , size : nil )
uistepper
SwiftIcons
// Setting icons
stepper.setDecrementIcon(icon: .ionicons(.iosPause), forState: .normal)
stepper.setIncrementIcon(icon: .ionicons(.iosPlay), forState: .normal)
\”>
import SwiftIcons // Setting icons stepper . setDecrementIcon ( icon : . ionicons ( . iosPause ) , forState : . normal ) stepper . setIncrementIcon ( icon : . ionicons ( . iosPlay ) , forState : . normal )
例子
请查看SwiftIcons应用程序。在演示项目中,如果单击任何对象,您将在该对象图标的日志中看到方法描述。
SwiftIcons提到和使用
- Zeba Rahman的Fabcoding文章,中等帖子中的相同内容:Fabcoding Medium Post
- 拉希尔·沙阿(Raheel Shah)的同学
- 开源项目,收集开源项目
- 在Awesome IOS上提及,这是令人敬畏的iOS生态系统的精心策划列表
- Malcolm Kumwenda的故事板上的中文文章
- 文章中使用的句子:从字面上看,这是我使用SwiftIcons库的唯一地方,但我认为展示一个很酷的库将是有益的,该图书馆使与Icons一起工作绝对很棒。
如果您在应用程序中使用SwiftIcons并希望在此处列出,请在此处创建一个新问题。
我总是很好奇谁在使用我的项目?
作者
Saurabh Rane
- 电子邮件
特别感谢Patrik Vaberer及其在Font-Awesome-Swift图书馆的最初工作
执照
SwiftIcons可根据MIT许可证获得。有关更多信息,请参见LICENSE文件。
