YFIconFont 4.2.0

YFIconFont 4.2.0

Maintained by Xiaoye__220.



  • By
  • Xiaoye__220

pod iOS lisence swift

IconFont

Use iconfont by Enum.Only support FontAwesome and custom iconfont currently(you can make a custom iconfont from iconfont.cniconmoon)

CocoaPods

use_frameworks!
pod 'YFIconFont'

Usage

ScreenShot

UILabel

label.iconFont(size: 25, icon: FontAwesome.github)

UIButton

button.iconFont(size: 30, icon: FontAwesome.weixin, color: color)

UIImage

We can create UIImage with fontSize or imageSize.One is created according to the size of the font. Another is created according to the size of the image.

// UIImage size is 39 * 30
imageView.image = UIImage.iconFont(fontSize: 30, icon: FontAwesome.ccvisa, color: color)

// image will scaled to fit with fixed aspect.
// UIImage size is 30 * 30
imageView2.image = UIImage.iconFont(imageSize: CGSize(width: 30, height: 30), icon: FontAwesome.ccvisa, color: color)

UIBarButtonItem

UIBarButtonItem needs to specify the type is image or title.

barButtonItem.iconFont(size: 25, icon: FontAwesome.apple, color: color, type: .image)

barButtonItem2.iconFont(size: 25, icon: FontAwesome.apple, color: color, type: .title)

UITabBarItem

leftTabBarItem.image = UIImage.iconFont(fontSize: 25, icon: FontAwesome.chrome)
leftTabBarItem.selectedImage = UIImage.iconFont(fontSize: 25, icon: FontAwesome.chrome, color: color).withRenderingMode(.alwaysOriginal)
leftTabBarItem.title = FontAwesome.chrome.rawValue

rightTabBarItem.image = UIImage.iconFont(fontSize: 25, icon: FontAwesome.firefox)
rightTabBarItem.selectedImage = UIImage.iconFont(fontSize: 25, icon: FontAwesome.firefox, color: color).withRenderingMode(.alwaysOriginal)
rightTabBarItem.title = FontAwesome.firefox.rawValue

Custom IconFont

Custom IconFont should implement protocol IconFontType

fontName:The fully specified name of the font. This name incorporates both the font family name and the specific style information for the font.

Create

public enum CustomIconFont: String {
    case feedback = "\u{e656}"
    case search = "\u{e651}"
    case home = "\u{e64f}"
    case clock = "\u{e648}"
    case like = "\u{e643}"
    case shoppingCart = "\u{e63f}"
}

extension CustomIconFont: IconFontType {

    public static var fontFilePath: String? = Bundle.main.path(forResource: "iconfont", ofType: "ttf")

    public static var fontName: String {
        return "iconfont"
        }

    public var unicode: String {
        return self.rawValue
    }
}

Usage

label1.iconFont(size: 25, icon: CustomIconFont.clock, color:color)
label2.iconFont(size: 30, icon: CustomIconFont.feedback, color: color)
label3.iconFont(size: 35, icon: CustomIconFont.shoppingCart, color: color)