Skip to content

Commit

Permalink
Add the options to only load fonts with name specified
Browse files Browse the repository at this point in the history
  • Loading branch information
UglyTroLL committed Feb 7, 2016
1 parent fd57054 commit 41def8f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Swicon/Swicon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
B912CFE21B4E6C6B002170CE /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0720;
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Zhibo Wei";
TargetAttributes = {
Expand Down Expand Up @@ -415,6 +417,7 @@
B912D0031B4E6C6B002170CE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
B912D0041B4E6C6B002170CE /* Build configuration list for PBXNativeTarget "SwiconTests" */ = {
isa = XCConfigurationList;
Expand All @@ -423,6 +426,7 @@
B912D0061B4E6C6B002170CE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
20 changes: 15 additions & 5 deletions Swicon/Swicon/Swicon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand All @@ -24,7 +23,6 @@ public class Swicon {
]

private init() {

}

public func addCustomFont(prefix: String, fontFileName: String, fontName: String, fontIconMap: [String: String]) {
Expand All @@ -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()
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions SwiconExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
B912CF841B4E69BF002170CE /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0720;
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Zhibo Wei";
TargetAttributes = {
Expand Down
9 changes: 5 additions & 4 deletions SwiconExample/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand All @@ -14,13 +15,13 @@
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Zhibo Wei. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="SwiconExample" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand Down
5 changes: 3 additions & 2 deletions SwiconExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pKB-vy-IL0">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pKB-vy-IL0">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down
9 changes: 5 additions & 4 deletions SwiconExample/IconCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Swicon

let cellIdentifier = "IconCell"

class IconCollectionViewController: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate {
class IconCollectionViewController: UICollectionViewController {

let iconNames = [
"fa-bed",
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
2 changes: 1 addition & 1 deletion SwiconExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 41def8f

Please sign in to comment.