From 41def8f4b1252f2aa8b246ff193c14d945c12677 Mon Sep 17 00:00:00 2001 From: Zhibo Wei Date: Sun, 7 Feb 2016 02:59:52 -0800 Subject: [PATCH] Add the options to only load fonts with name specified --- Swicon/Swicon.xcodeproj/project.pbxproj | 4 ++++ Swicon/Swicon/Swicon.swift | 20 ++++++++++++++----- SwiconExample.xcodeproj/project.pbxproj | 2 ++ SwiconExample/Base.lproj/LaunchScreen.xib | 9 +++++---- SwiconExample/Base.lproj/Main.storyboard | 5 +++-- .../IconCollectionViewController.swift | 9 +++++---- .../AppIcon.appiconset/Contents.json | 5 +++++ SwiconExample/ViewController.swift | 2 +- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Swicon/Swicon.xcodeproj/project.pbxproj b/Swicon/Swicon.xcodeproj/project.pbxproj index 0f11328..87a4841 100644 --- a/Swicon/Swicon.xcodeproj/project.pbxproj +++ b/Swicon/Swicon.xcodeproj/project.pbxproj @@ -170,6 +170,8 @@ B912CFE21B4E6C6B002170CE /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0720; + LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0630; ORGANIZATIONNAME = "Zhibo Wei"; TargetAttributes = { @@ -415,6 +417,7 @@ B912D0031B4E6C6B002170CE /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; B912D0041B4E6C6B002170CE /* Build configuration list for PBXNativeTarget "SwiconTests" */ = { isa = XCConfigurationList; @@ -423,6 +426,7 @@ B912D0061B4E6C6B002170CE /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Swicon/Swicon/Swicon.swift b/Swicon/Swicon/Swicon.swift index 3d0c786..8a53720 100644 --- a/Swicon/Swicon/Swicon.swift +++ b/Swicon/Swicon/Swicon.swift @@ -15,7 +15,6 @@ public class Swicon { public static let instance = Swicon() - private var fontAwesoneLoaded = false, googleMaterialLoaded = false, customFontLoaded = false private let load_queue = dispatch_queue_create("com.swicon.font.load.queue", DISPATCH_QUEUE_SERIAL) private var fontsMap :[String: IconFont] = [ @@ -24,7 +23,6 @@ public class Swicon { ] private init() { - } public func addCustomFont(prefix: String, fontFileName: String, fontName: String, fontIconMap: [String: String]) { @@ -33,13 +31,25 @@ public class Swicon { public func loadAllAsync() { dispatch_async(self.load_queue, { - self.loadAllSync() + self.loadAllSync([String](self.fontsMap.keys)) + }) + } + + public func loadAllAsync(fontNames:[String]) { + dispatch_async(self.load_queue, { + self.loadAllSync(fontNames) }) } public func loadAllSync() { - for font in fontsMap.values { - font.loadFontIfNecessary() + self.loadAllSync([String](fontsMap.keys)) + } + + public func loadAllSync(fontNames:[String]) { + for fontName in fontNames { + if let font = fontsMap[fontName] { + font.loadFontIfNecessary() + } } } diff --git a/SwiconExample.xcodeproj/project.pbxproj b/SwiconExample.xcodeproj/project.pbxproj index 945a8da..15e60a1 100644 --- a/SwiconExample.xcodeproj/project.pbxproj +++ b/SwiconExample.xcodeproj/project.pbxproj @@ -189,6 +189,8 @@ B912CF841B4E69BF002170CE /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0720; + LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0630; ORGANIZATIONNAME = "Zhibo Wei"; TargetAttributes = { diff --git a/SwiconExample/Base.lproj/LaunchScreen.xib b/SwiconExample/Base.lproj/LaunchScreen.xib index d58fcb7..1404565 100644 --- a/SwiconExample/Base.lproj/LaunchScreen.xib +++ b/SwiconExample/Base.lproj/LaunchScreen.xib @@ -1,7 +1,8 @@ - + - + + @@ -14,13 +15,13 @@ diff --git a/SwiconExample/Base.lproj/Main.storyboard b/SwiconExample/Base.lproj/Main.storyboard index b2355fb..0432415 100644 --- a/SwiconExample/Base.lproj/Main.storyboard +++ b/SwiconExample/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + diff --git a/SwiconExample/IconCollectionViewController.swift b/SwiconExample/IconCollectionViewController.swift index 6b85e42..f011f6e 100644 --- a/SwiconExample/IconCollectionViewController.swift +++ b/SwiconExample/IconCollectionViewController.swift @@ -12,7 +12,7 @@ import Swicon let cellIdentifier = "IconCell" -class IconCollectionViewController: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate { +class IconCollectionViewController: UICollectionViewController { let iconNames = [ "fa-bed", @@ -79,15 +79,16 @@ class IconCollectionViewController: UICollectionViewController, UICollectionView override func viewDidLoad() { super.viewDidLoad() + Swicon.instance.loadAllSync(["gm"]) for iconName in iconNames { iconImages.append(Swicon.instance.getUIImage(iconName, iconSize: 45, iconColour: getRandomColor(), imageSize: CGSizeMake(48, 48))) } } func getRandomColor() -> UIColor{ - var randomRed:CGFloat = CGFloat(drand48()) - var randomGreen:CGFloat = CGFloat(drand48()) - var randomBlue:CGFloat = CGFloat(drand48()) + let randomRed:CGFloat = CGFloat(drand48()) + let randomGreen:CGFloat = CGFloat(drand48()) + let randomBlue:CGFloat = CGFloat(drand48()) return UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0) } diff --git a/SwiconExample/Images.xcassets/AppIcon.appiconset/Contents.json b/SwiconExample/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..eeea76c 100644 --- a/SwiconExample/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/SwiconExample/Images.xcassets/AppIcon.appiconset/Contents.json @@ -59,6 +59,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/SwiconExample/ViewController.swift b/SwiconExample/ViewController.swift index 77a3322..826aed6 100644 --- a/SwiconExample/ViewController.swift +++ b/SwiconExample/ViewController.swift @@ -16,7 +16,7 @@ class ViewController: UIViewController { @IBOutlet weak var btn: UIButton! override func viewDidLoad() { super.viewDidLoad() - Swicon.instance.loadAllSync() + Swicon.instance.loadAllSync(["gm"]) label.attributedText = Swicon.instance.getNSMutableAttributedString("gm-games", fontSize: 10) btn.setAttributedTitle(Swicon.instance.getNSMutableAttributedString("fa-eur", fontSize: 10), forState: .Normal) img.image = Swicon.instance.getUIImage("fa-heart", iconSize: 100, iconColour: UIColor.blueColor(), imageSize: CGSizeMake(200, 200))