diff --git a/.DS_Store b/.DS_Store index e3fdcde..aa1bb18 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Fonty-Demo/Fonty-Demo.xcodeproj/project.pbxproj b/Fonty-Demo.xcodeproj/project.pbxproj similarity index 75% rename from Fonty-Demo/Fonty-Demo.xcodeproj/project.pbxproj rename to Fonty-Demo.xcodeproj/project.pbxproj index d7ae598..d0414a5 100644 --- a/Fonty-Demo/Fonty-Demo.xcodeproj/project.pbxproj +++ b/Fonty-Demo.xcodeproj/project.pbxproj @@ -13,12 +13,14 @@ 6A73D6BA1D86BB2600D38630 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A73D6B81D86BB2600D38630 /* Main.storyboard */; }; 6A73D6BC1D86BB2600D38630 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A73D6BB1D86BB2600D38630 /* Assets.xcassets */; }; 6A73D6BF1D86BB2600D38630 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6A73D6BD1D86BB2600D38630 /* LaunchScreen.storyboard */; }; - 6A73D6D41D86BB6500D38630 /* FYFontCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6C81D86BB6500D38630 /* FYFontCache.m */; }; - 6A73D6D51D86BB6500D38630 /* FYFontDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6CA1D86BB6500D38630 /* FYFontDownloader.m */; }; - 6A73D6D61D86BB6500D38630 /* FYFontManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6CC1D86BB6500D38630 /* FYFontManager.m */; }; - 6A73D6D71D86BB6500D38630 /* FYFontModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6CE1D86BB6500D38630 /* FYFontModel.m */; }; - 6A73D6D81D86BB6500D38630 /* FYFontRegister.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6D01D86BB6500D38630 /* FYFontRegister.m */; }; - 6A73D6D91D86BB6500D38630 /* UIFont+FY_Fonty.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6D31D86BB6500D38630 /* UIFont+FY_Fonty.m */; }; + 6A73D6E81D86C05000D38630 /* FYFontCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6DC1D86C05000D38630 /* FYFontCache.m */; }; + 6A73D6E91D86C05000D38630 /* FYFontDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6DE1D86C05000D38630 /* FYFontDownloader.m */; }; + 6A73D6EA1D86C05000D38630 /* FYFontManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6E01D86C05000D38630 /* FYFontManager.m */; }; + 6A73D6EB1D86C05000D38630 /* FYFontModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6E21D86C05000D38630 /* FYFontModel.m */; }; + 6A73D6EC1D86C05000D38630 /* FYFontRegister.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6E41D86C05000D38630 /* FYFontRegister.m */; }; + 6A73D6ED1D86C05000D38630 /* UIFont+FY_Fonty.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6E71D86C05000D38630 /* UIFont+FY_Fonty.m */; }; + 6A73D6F21D86C09500D38630 /* FYSelectFontViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6EF1D86C09500D38630 /* FYSelectFontViewController.m */; }; + 6A73D6F31D86C09500D38630 /* FYSelectFontTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A73D6F11D86C09500D38630 /* FYSelectFontTableViewCell.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,19 +34,23 @@ 6A73D6BB1D86BB2600D38630 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 6A73D6BE1D86BB2600D38630 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 6A73D6C01D86BB2600D38630 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 6A73D6C71D86BB6500D38630 /* FYFontCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontCache.h; sourceTree = ""; }; - 6A73D6C81D86BB6500D38630 /* FYFontCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontCache.m; sourceTree = ""; }; - 6A73D6C91D86BB6500D38630 /* FYFontDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontDownloader.h; sourceTree = ""; }; - 6A73D6CA1D86BB6500D38630 /* FYFontDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontDownloader.m; sourceTree = ""; }; - 6A73D6CB1D86BB6500D38630 /* FYFontManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontManager.h; sourceTree = ""; }; - 6A73D6CC1D86BB6500D38630 /* FYFontManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontManager.m; sourceTree = ""; }; - 6A73D6CD1D86BB6500D38630 /* FYFontModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontModel.h; sourceTree = ""; }; - 6A73D6CE1D86BB6500D38630 /* FYFontModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontModel.m; sourceTree = ""; }; - 6A73D6CF1D86BB6500D38630 /* FYFontRegister.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontRegister.h; sourceTree = ""; }; - 6A73D6D01D86BB6500D38630 /* FYFontRegister.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontRegister.m; sourceTree = ""; }; - 6A73D6D11D86BB6500D38630 /* FYHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYHeader.h; sourceTree = ""; }; - 6A73D6D21D86BB6500D38630 /* UIFont+FY_Fonty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIFont+FY_Fonty.h"; sourceTree = ""; }; - 6A73D6D31D86BB6500D38630 /* UIFont+FY_Fonty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+FY_Fonty.m"; sourceTree = ""; }; + 6A73D6DB1D86C05000D38630 /* FYFontCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontCache.h; sourceTree = ""; }; + 6A73D6DC1D86C05000D38630 /* FYFontCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontCache.m; sourceTree = ""; }; + 6A73D6DD1D86C05000D38630 /* FYFontDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontDownloader.h; sourceTree = ""; }; + 6A73D6DE1D86C05000D38630 /* FYFontDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontDownloader.m; sourceTree = ""; }; + 6A73D6DF1D86C05000D38630 /* FYFontManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontManager.h; sourceTree = ""; }; + 6A73D6E01D86C05000D38630 /* FYFontManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontManager.m; sourceTree = ""; }; + 6A73D6E11D86C05000D38630 /* FYFontModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontModel.h; sourceTree = ""; }; + 6A73D6E21D86C05000D38630 /* FYFontModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontModel.m; sourceTree = ""; }; + 6A73D6E31D86C05000D38630 /* FYFontRegister.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYFontRegister.h; sourceTree = ""; }; + 6A73D6E41D86C05000D38630 /* FYFontRegister.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYFontRegister.m; sourceTree = ""; }; + 6A73D6E51D86C05000D38630 /* FYHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYHeader.h; sourceTree = ""; }; + 6A73D6E61D86C05000D38630 /* UIFont+FY_Fonty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIFont+FY_Fonty.h"; sourceTree = ""; }; + 6A73D6E71D86C05000D38630 /* UIFont+FY_Fonty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+FY_Fonty.m"; sourceTree = ""; }; + 6A73D6EE1D86C09500D38630 /* FYSelectFontViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYSelectFontViewController.h; sourceTree = ""; }; + 6A73D6EF1D86C09500D38630 /* FYSelectFontViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYSelectFontViewController.m; sourceTree = ""; }; + 6A73D6F01D86C09500D38630 /* FYSelectFontTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FYSelectFontTableViewCell.h; sourceTree = ""; }; + 6A73D6F11D86C09500D38630 /* FYSelectFontTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FYSelectFontTableViewCell.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -62,7 +68,7 @@ isa = PBXGroup; children = ( 6A73D6AE1D86BB2600D38630 /* Fonty-Demo */, - 6A73D6C61D86BB6500D38630 /* Fonty */, + 6A73D6DA1D86C05000D38630 /* Fonty */, 6A73D6AD1D86BB2600D38630 /* Products */, ); sourceTree = ""; @@ -82,6 +88,10 @@ 6A73D6B31D86BB2600D38630 /* AppDelegate.m */, 6A73D6B51D86BB2600D38630 /* ViewController.h */, 6A73D6B61D86BB2600D38630 /* ViewController.m */, + 6A73D6EE1D86C09500D38630 /* FYSelectFontViewController.h */, + 6A73D6EF1D86C09500D38630 /* FYSelectFontViewController.m */, + 6A73D6F01D86C09500D38630 /* FYSelectFontTableViewCell.h */, + 6A73D6F11D86C09500D38630 /* FYSelectFontTableViewCell.m */, 6A73D6B81D86BB2600D38630 /* Main.storyboard */, 6A73D6BB1D86BB2600D38630 /* Assets.xcassets */, 6A73D6BD1D86BB2600D38630 /* LaunchScreen.storyboard */, @@ -99,22 +109,22 @@ name = "Supporting Files"; sourceTree = ""; }; - 6A73D6C61D86BB6500D38630 /* Fonty */ = { + 6A73D6DA1D86C05000D38630 /* Fonty */ = { isa = PBXGroup; children = ( - 6A73D6C71D86BB6500D38630 /* FYFontCache.h */, - 6A73D6C81D86BB6500D38630 /* FYFontCache.m */, - 6A73D6C91D86BB6500D38630 /* FYFontDownloader.h */, - 6A73D6CA1D86BB6500D38630 /* FYFontDownloader.m */, - 6A73D6CB1D86BB6500D38630 /* FYFontManager.h */, - 6A73D6CC1D86BB6500D38630 /* FYFontManager.m */, - 6A73D6CD1D86BB6500D38630 /* FYFontModel.h */, - 6A73D6CE1D86BB6500D38630 /* FYFontModel.m */, - 6A73D6CF1D86BB6500D38630 /* FYFontRegister.h */, - 6A73D6D01D86BB6500D38630 /* FYFontRegister.m */, - 6A73D6D11D86BB6500D38630 /* FYHeader.h */, - 6A73D6D21D86BB6500D38630 /* UIFont+FY_Fonty.h */, - 6A73D6D31D86BB6500D38630 /* UIFont+FY_Fonty.m */, + 6A73D6DB1D86C05000D38630 /* FYFontCache.h */, + 6A73D6DC1D86C05000D38630 /* FYFontCache.m */, + 6A73D6DD1D86C05000D38630 /* FYFontDownloader.h */, + 6A73D6DE1D86C05000D38630 /* FYFontDownloader.m */, + 6A73D6DF1D86C05000D38630 /* FYFontManager.h */, + 6A73D6E01D86C05000D38630 /* FYFontManager.m */, + 6A73D6E11D86C05000D38630 /* FYFontModel.h */, + 6A73D6E21D86C05000D38630 /* FYFontModel.m */, + 6A73D6E31D86C05000D38630 /* FYFontRegister.h */, + 6A73D6E41D86C05000D38630 /* FYFontRegister.m */, + 6A73D6E51D86C05000D38630 /* FYHeader.h */, + 6A73D6E61D86C05000D38630 /* UIFont+FY_Fonty.h */, + 6A73D6E71D86C05000D38630 /* UIFont+FY_Fonty.m */, ); path = Fonty; sourceTree = ""; @@ -189,15 +199,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6A73D6F21D86C09500D38630 /* FYSelectFontViewController.m in Sources */, 6A73D6B71D86BB2600D38630 /* ViewController.m in Sources */, 6A73D6B41D86BB2600D38630 /* AppDelegate.m in Sources */, - 6A73D6D41D86BB6500D38630 /* FYFontCache.m in Sources */, - 6A73D6D61D86BB6500D38630 /* FYFontManager.m in Sources */, - 6A73D6D51D86BB6500D38630 /* FYFontDownloader.m in Sources */, + 6A73D6E81D86C05000D38630 /* FYFontCache.m in Sources */, + 6A73D6EA1D86C05000D38630 /* FYFontManager.m in Sources */, + 6A73D6F31D86C09500D38630 /* FYSelectFontTableViewCell.m in Sources */, + 6A73D6E91D86C05000D38630 /* FYFontDownloader.m in Sources */, 6A73D6B11D86BB2600D38630 /* main.m in Sources */, - 6A73D6D81D86BB6500D38630 /* FYFontRegister.m in Sources */, - 6A73D6D91D86BB6500D38630 /* UIFont+FY_Fonty.m in Sources */, - 6A73D6D71D86BB6500D38630 /* FYFontModel.m in Sources */, + 6A73D6EC1D86C05000D38630 /* FYFontRegister.m in Sources */, + 6A73D6ED1D86C05000D38630 /* UIFont+FY_Fonty.m in Sources */, + 6A73D6EB1D86C05000D38630 /* FYFontModel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -312,6 +324,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "Fonty-Demo/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "s2mh.Fonty-Demo"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -323,6 +336,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "Fonty-Demo/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "s2mh.Fonty-Demo"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -348,6 +362,7 @@ 6A73D6C51D86BB2600D38630 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Fonty-Demo/Fonty-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Fonty-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from Fonty-Demo/Fonty-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Fonty-Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate b/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..41d9ec2 Binary files /dev/null and b/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/Fonty-Demo/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/Fonty-Demo.xcscheme b/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/Fonty-Demo.xcscheme similarity index 100% rename from Fonty-Demo/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/Fonty-Demo.xcscheme rename to Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/Fonty-Demo.xcscheme diff --git a/Fonty-Demo/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/xcschememanagement.plist b/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/xcschememanagement.plist similarity index 100% rename from Fonty-Demo/Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/xcschememanagement.plist rename to Fonty-Demo.xcodeproj/xcuserdata/yanweichen.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/Fonty-Demo/Fonty-Demo/AppDelegate.h b/Fonty-Demo/AppDelegate.h similarity index 100% rename from Fonty-Demo/Fonty-Demo/AppDelegate.h rename to Fonty-Demo/AppDelegate.h diff --git a/Fonty-Demo/Fonty-Demo/AppDelegate.m b/Fonty-Demo/AppDelegate.m similarity index 100% rename from Fonty-Demo/Fonty-Demo/AppDelegate.m rename to Fonty-Demo/AppDelegate.m diff --git a/Fonty-Demo/Fonty-Demo/Assets.xcassets/AppIcon.appiconset/Contents.json b/Fonty-Demo/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from Fonty-Demo/Fonty-Demo/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Fonty-Demo/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/Fonty-Demo/Fonty-Demo/Base.lproj/LaunchScreen.storyboard b/Fonty-Demo/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from Fonty-Demo/Fonty-Demo/Base.lproj/LaunchScreen.storyboard rename to Fonty-Demo/Base.lproj/LaunchScreen.storyboard diff --git a/Fonty-Demo/Fonty-Demo/Base.lproj/Main.storyboard b/Fonty-Demo/Base.lproj/Main.storyboard similarity index 100% rename from Fonty-Demo/Fonty-Demo/Base.lproj/Main.storyboard rename to Fonty-Demo/Base.lproj/Main.storyboard diff --git a/Fonty-Demo/FYSelectFontTableViewCell.h b/Fonty-Demo/FYSelectFontTableViewCell.h new file mode 100644 index 0000000..7025270 --- /dev/null +++ b/Fonty-Demo/FYSelectFontTableViewCell.h @@ -0,0 +1,13 @@ +// +// FYSelectFontTableViewCell.h +// Fonty +// +// Created by 颜为晨 on 9/9/16. +// Copyright © 2016 颜为晨. All rights reserved. +// + +#import + +@interface FYSelectFontTableViewCell : UITableViewCell + +@end diff --git a/Fonty-Demo/FYSelectFontTableViewCell.m b/Fonty-Demo/FYSelectFontTableViewCell.m new file mode 100644 index 0000000..a98dc77 --- /dev/null +++ b/Fonty-Demo/FYSelectFontTableViewCell.m @@ -0,0 +1,16 @@ + +// +// FYSelectFontTableViewCell.m +// Fonty +// +// Created by 颜为晨 on 9/9/16. +// Copyright © 2016 颜为晨. All rights reserved. +// + +#import "FYSelectFontTableViewCell.h" + +@implementation FYSelectFontTableViewCell + +//- () + +@end diff --git a/Fonty-Demo/FYSelectFontViewController.h b/Fonty-Demo/FYSelectFontViewController.h new file mode 100644 index 0000000..df3e1c9 --- /dev/null +++ b/Fonty-Demo/FYSelectFontViewController.h @@ -0,0 +1,13 @@ +// +// FYSelectFontViewController.h +// Fonty +// +// Created by 颜为晨 on 9/9/16. +// Copyright © 2016 颜为晨. All rights reserved. +// + +#import + +@interface FYSelectFontViewController : UITableViewController + +@end diff --git a/Fonty-Demo/FYSelectFontViewController.m b/Fonty-Demo/FYSelectFontViewController.m new file mode 100644 index 0000000..c14081d --- /dev/null +++ b/Fonty-Demo/FYSelectFontViewController.m @@ -0,0 +1,133 @@ +// +// FYSelectFontViewController.m +// Fonty +// +// Created by 颜为晨 on 9/9/16. +// Copyright © 2016 颜为晨. All rights reserved. +// + +#import "FYSelectFontViewController.h" +#import "FYHeader.h" + +static NSString *const UITableViewCellIdentifier = @"UITableViewCellIdentifier"; + +@interface FYSelectFontViewController () + +@property (nonatomic, weak) FYFontManager *fontManager; +@property (nonatomic, weak) NSArray *fontModelArray; + +@end + +@implementation FYSelectFontViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.navigationItem.title = @"Fonty"; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" + style:UIBarButtonItemStyleDone + target:self + action:@selector(backAction)]; + + self.fontManager = [FYFontManager sharedManager]; + self.fontModelArray = self.fontManager.fontModelArray; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:UITableViewCellIdentifier]; +} + +#pragma mark - UITableViewDataSource + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.fontModelArray.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + FYFontModel *model = [self.fontModelArray objectAtIndex:indexPath.row]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UITableViewCellIdentifier forIndexPath:indexPath]; + + cell.selectionStyle = UITableViewCellSelectionStyleBlue; + cell.textLabel.text = model.description; + cell.accessoryView = nil; + + if (model.status == FYFontModelDownloadStatusDownloaded) { + if (indexPath.row == self.fontManager.mainFontIndex) { + cell.selected = YES; + } + } else if (model.status == FYFontModelDownloadStatusDeleting || model.status == FYFontModelDownloadStatusDownloading) { + UIActivityIndicatorView *AIV = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; + [AIV startAnimating]; + cell.accessoryView = AIV; + } + + return cell; +} + +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + FYFontModel *model = [self.fontModelArray objectAtIndex:indexPath.row]; + return model.status == FYFontModelDownloadStatusDownloaded; +} + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + + FYFontModel *model = [self.fontModelArray objectAtIndex:indexPath.row]; + model.status = FYFontModelDownloadStatusDeleting; + [tableView reloadData]; + + [self.fontManager deleteFontWithURL:model.URL completeBlock:^{ + model.status = FYFontModelDownloadStatusToBeDownloaded; + self.fontManager.mainFontIndex = 0; + [tableView reloadData]; + }]; + } +} + +#pragma mark UITableViewDelegate + +- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { + FYFontModel *model = [self.fontModelArray objectAtIndex:indexPath.row]; + if (model.status == FYFontModelDownloadStatusDownloaded) { + self.fontManager.mainFontIndex = indexPath.row; + [tableView reloadData]; + return indexPath; + } else { + UIAlertView *AV = [[UIAlertView alloc] initWithTitle:@"Download Font File from" + message:model.URL.absoluteString + delegate:self + cancelButtonTitle:@"cancel" + otherButtonTitles:@"start", nil]; + AV.tag = indexPath.row; + [AV show]; + return nil; + } +} + +- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { + return @"clear"; +} + +- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { + FYFontModel *model = [self.fontModelArray objectAtIndex:indexPath.row]; + if (model.status == FYFontModelDownloadStatusDownloaded || model.URL) { + return UITableViewCellEditingStyleDelete; + } else { + return UITableViewCellEditingStyleNone; + } +} + +#pragma mark UIAlertViewDelegate + +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { + if (buttonIndex == 1) { + FYFontModel *model = [self.fontModelArray objectAtIndex:alertView.tag]; + [self.fontManager downloadFontWithURL:model.URL]; + } +} + +#pragma mark - Action + +- (void)backAction { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +@end diff --git a/Fonty-Demo/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate b/Fonty-Demo/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index a1bcaa2..0000000 Binary files a/Fonty-Demo/Fonty-Demo.xcodeproj/project.xcworkspace/xcuserdata/yanweichen.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/Fonty-Demo/Fonty-Demo/ViewController.m b/Fonty-Demo/Fonty-Demo/ViewController.m deleted file mode 100644 index d1bd091..0000000 --- a/Fonty-Demo/Fonty-Demo/ViewController.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// ViewController.m -// Fonty-Demo -// -// Created by 颜为晨 on 9/12/16. -// Copyright © 2016 s2mh. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -@end diff --git a/Fonty-Demo/Fonty/FYFontCache.h b/Fonty-Demo/Fonty/FYFontCache.h deleted file mode 100644 index 5925c86..0000000 --- a/Fonty-Demo/Fonty/FYFontCache.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// FYFontCache.h -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import -#import - -@interface FYFontCache : NSObject - -@property (nonatomic, copy, readonly) NSString *diskCacheDirectoryPath; - -+ (instancetype)sharedFontCache; - -- (NSString *)cachedFilePathWithWebURL:(NSURL *)webURL; -- (NSString *)cacheFileAtLocolURL:(NSURL *)locolURL fromWebURL:(NSURL *)webURL; -- (void)cleanCachedFileWithWebURL:(NSURL *)webURL; - -@end diff --git a/Fonty-Demo/Fonty/FYFontCache.m b/Fonty-Demo/Fonty/FYFontCache.m deleted file mode 100644 index b8c31b0..0000000 --- a/Fonty-Demo/Fonty/FYFontCache.m +++ /dev/null @@ -1,112 +0,0 @@ -// -// FYFontCache.m -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import -#import "FYFontCache.h" - -static NSString * const FTFontCacheDirectoryName = @"FTFont"; - -@interface FYFontCache () - -@property (nonatomic, copy, readwrite) NSString *diskCacheDirectoryPath; -@property (nonatomic, strong) NSMutableDictionary *cachePaths; // key = URLString, object = fontFileName -@property (nonatomic, weak) NSFileManager *fileManager; - -@end - -@implementation FYFontCache - -+ (instancetype)sharedFontCache { - static id instance; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - instance = [self new]; - }); - return instance; -} - -- (instancetype)init -{ - self = [super init]; - if (self) { - _fileManager = [NSFileManager defaultManager]; - } - return self; -} - -#pragma mark - Public - -- (NSString *)cachedFilePathWithWebURL:(NSURL *)webURL { - NSString *filePath = [self cachedFilePathForWebURLString:webURL.absoluteString]; - if ([self.fileManager fileExistsAtPath:filePath]) { - return filePath; - } else { - return nil; - } -} - -- (NSString *)cacheFileAtLocolURL:(NSURL *)locolURL fromWebURL:(NSURL *)webURL { - NSString *filePath = [self cachedFilePathForWebURLString:webURL.absoluteString]; - if (![self.fileManager fileExistsAtPath:filePath]) { - [self.fileManager removeItemAtPath:filePath error:NULL]; - } - NSURL *docsDirURL = [NSURL fileURLWithPath:filePath]; - [self.fileManager moveItemAtURL:locolURL - toURL:docsDirURL - error:NULL]; - return filePath; -} - -- (void)cleanCachedFileWithWebURL:(NSURL *)webURL { - NSString *filePath = [self cachedFilePathForWebURLString:webURL.absoluteString]; - [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; -} - -#pragma mark - Private - -- (NSString *)cachedFilePathForWebURLString:(NSString *)URLString { - NSString *fontFileName = [self.cachePaths objectForKey:URLString]; - if (!fontFileName) { - const char *str = [URLString UTF8String]; - if (str == NULL) { - return @""; - } - unsigned char r[CC_MD5_DIGEST_LENGTH]; - CC_MD5(str, (CC_LONG)strlen(str), r); - fontFileName = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], - r[11], r[12], r[13], r[14], r[15]]; - [self.cachePaths setObject:fontFileName forKey:URLString]; - } - - return [self.diskCacheDirectoryPath stringByAppendingPathComponent:fontFileName]; -} - - -#pragma mark - accessor - -- (NSString *)diskCacheDirectoryPath { - if (!_diskCacheDirectoryPath) { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); - _diskCacheDirectoryPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:FTFontCacheDirectoryName]; - [self.fileManager createDirectoryAtPath:_diskCacheDirectoryPath - withIntermediateDirectories:YES - attributes:nil - error:nil]; - } - return _diskCacheDirectoryPath; -} - -- (NSMutableDictionary *)cachePaths { - if (!_cachePaths) { - _cachePaths = [NSMutableDictionary dictionary]; - } - return _cachePaths; -} - -@end diff --git a/Fonty-Demo/Fonty/FYFontDownloader.h b/Fonty-Demo/Fonty/FYFontDownloader.h deleted file mode 100644 index 7f8bae4..0000000 --- a/Fonty-Demo/Fonty/FYFontDownloader.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// FYFontDownloader.h -// Fonty -// -// Created by 颜为晨 on 9/9/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import - -extern NSString *const FYNewFontDownloadNotification; -extern NSString *const FYNewFontDownloadNotificationKey; - -@interface FYFontDownloader : NSObject - -+ (instancetype)sharedDownloader; - -- (void)downloadFontWithURL:(NSURL *)URL; - -@end diff --git a/Fonty-Demo/Fonty/FYFontDownloader.m b/Fonty-Demo/Fonty/FYFontDownloader.m deleted file mode 100644 index 391d2a2..0000000 --- a/Fonty-Demo/Fonty/FYFontDownloader.m +++ /dev/null @@ -1,80 +0,0 @@ -// -// FYFontDownloader.m -// Fonty -// -// Created by 颜为晨 on 9/9/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import "FYFontDownloader.h" -#import "FYFontCache.h" -#import "FYFontModel.h" - -NSString *const FYNewFontDownloadNotification = @"FYNewFontDownloadNotification"; -NSString *const FYNewFontDownloadNotificationKey = @"FYNewFontDownloadNotificationKey"; // FYDowloadFontModel - -@interface FYFontDownloader () - -@property (nonatomic, strong) NSURLSession *session; - -@end - -@implementation FYFontDownloader - -+ (instancetype)sharedDownloader { - static id instance; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - instance = [self new]; - }); - return instance; -} - -- (void)downloadFontWithURL:(NSURL *)URL { - NSURLSessionDownloadTask *task = [self.session downloadTaskWithURL:URL]; - [task resume]; -} - -#pragma mark - NSURLSessionDownloadDelegate - -- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { - NSString *path = [[FYFontCache sharedFontCache] cacheFileAtLocolURL:location fromWebURL:downloadTask.originalRequest.URL]; - if (path) { - dispatch_async(dispatch_get_main_queue(), ^{ - FYFontModel *model = [FYFontModel modelWithURL:downloadTask.originalRequest.URL - status:FYFontModelDownloadStatusDownloaded - downloadProgress:1.0f]; - NSDictionary *userInfo = @{FYNewFontDownloadNotificationKey:model}; - [[NSNotificationCenter defaultCenter] postNotificationName:FYNewFontDownloadNotification object:self userInfo:userInfo]; - }); - } -} - -- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask - didWriteData:(int64_t)bytesWritten - totalBytesWritten:(int64_t)totalBytesWritten -totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { - NSLog(@"%f", ((float)totalBytesWritten / totalBytesExpectedToWrite)); - if (totalBytesExpectedToWrite != NSURLSessionTransferSizeUnknown) { - dispatch_async(dispatch_get_main_queue(), ^{ - FYFontModel *model = [FYFontModel modelWithURL:downloadTask.originalRequest.URL - status:FYFontModelDownloadStatusDownloading - downloadProgress:(float)totalBytesWritten / totalBytesExpectedToWrite]; - NSDictionary *userInfo = @{FYNewFontDownloadNotificationKey:model}; - [[NSNotificationCenter defaultCenter] postNotificationName:FYNewFontDownloadNotification object:self userInfo:userInfo]; - }); - } -} - -#pragma mark - accessor - -- (NSURLSession *)session { - if (!_session) { - _session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] - delegate:self - delegateQueue:nil]; - } - return _session; -} - -@end diff --git a/Fonty-Demo/Fonty/FYFontManager.h b/Fonty-Demo/Fonty/FYFontManager.h deleted file mode 100644 index 2ec37f2..0000000 --- a/Fonty-Demo/Fonty/FYFontManager.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// FYFontManager.h -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import -#import - -@class FYFontModel; - -extern const NSInteger FYUsingSystemFontIndex; - -@interface FYFontManager : NSObject - -+ (instancetype)sharedManager; - -- (UIFont *)fontWithURL:(NSURL *)URL size:(CGFloat)size; -- (UIFont *)fontWithURLString:(NSString *)URLString size:(CGFloat)size; - -- (UIFont *)mainFontOfSize:(CGFloat)size; -@property (nonatomic, strong) NSArray *fontURLStringArray; -@property (nonatomic, assign) NSInteger mainFontIndex; -@property (nonatomic, strong, readonly) NSArray *fontModelArray; - -- (void)downloadFontWithURL:(NSURL *)URL; -- (void)downloadFontWithURLString:(NSString *)URLString; -- (void)deleteFontWithURL:(NSURL *)URL completeBlock:(void(^)())completeBlock; -- (void)deleteFontWithURLString:(NSString *)URLString completeBlock:(void(^)())completeBlock; - -@end diff --git a/Fonty-Demo/Fonty/FYFontManager.m b/Fonty-Demo/Fonty/FYFontManager.m deleted file mode 100644 index 1245438..0000000 --- a/Fonty-Demo/Fonty/FYFontManager.m +++ /dev/null @@ -1,175 +0,0 @@ -// -// FYFontManager.m -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import "FYFontManager.h" -#import "FYFontCache.h" -#import "FYFontRegister.h" -#import "FYFontDownloader.h" -#import "FYFontModel.h" - -const NSInteger FYUsingSystemFontIndex = NSIntegerMin; - -@interface FYFontManager () - -@property (nonatomic, strong) FYFontCache *fontCache; -@property (nonatomic, strong) FYFontDownloader *fontDownloader; -@property (nonatomic, strong) FYFontRegister *fontRegister; - -@property (nonatomic, strong) NSMutableDictionary *postScriptNames; // key = URL.absoluteString, object = postScriptName - -@property (nonatomic, strong, readwrite) NSArray *fontModelArray; - -@end - -@implementation FYFontManager - -+ (instancetype)sharedManager { - static id instance; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - instance = [self new]; - }); - return instance; -} - -- (instancetype)init -{ - self = [super init]; - if (self) { - _fontCache = [FYFontCache sharedFontCache]; - _fontDownloader = [FYFontDownloader sharedDownloader]; - _fontRegister = [FYFontRegister sharedRegister]; - _mainFontIndex = FYUsingSystemFontIndex; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(changeModelStatus:) - name:FYNewFontDownloadNotification - object:_fontDownloader]; - } - return self; -} - -#pragma mark - Public - -- (UIFont *)fontWithURL:(NSURL *)URL size:(CGFloat)size { - if (![URL isKindOfClass:NSURL.class]) { - return [UIFont systemFontOfSize:size]; - } - - NSString *postScriptName = [self.postScriptNames objectForKey:URL.absoluteString]; - UIFont *font = [UIFont fontWithName:postScriptName size:size]; - - if (![font.fontName isEqualToString:postScriptName]) { - - if (!postScriptName) { - // searching postScriptName in cache - NSString *cachePath = [self.fontCache cachedFilePathWithWebURL:URL]; - if (cachePath) { - postScriptName = [self.fontRegister registerFontWithPath:cachePath completeBlock:^(NSString *registeredPostScriptName){ - [self.postScriptNames setObject:registeredPostScriptName forKey:URL.absoluteString]; - [self.fontModelArray enumerateObjectsUsingBlock:^(FYFontModel * _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) { - if ([model.URL isEqual:URL]) { - model.postScriptName = registeredPostScriptName; - } - }]; - }]; - } - } - - if (postScriptName) { - // found postScriptName - font = [UIFont fontWithName:postScriptName size:size]; - } - } - - return font; -} - -- (UIFont *)fontWithURLString:(NSString *)URLString size:(CGFloat)size { - return [self fontWithURL:[NSURL URLWithString:URLString] size:size]; -} - -- (UIFont *)mainFontOfSize:(CGFloat)size { - if (self.mainFontIndex < 0 || self.mainFontIndex > self.fontModelArray.count) { - return [UIFont systemFontOfSize:size]; - } - FYFontModel *model = [self.fontModelArray objectAtIndex:self.mainFontIndex]; - return [self fontWithURL:model.URL size:size]; -} - -- (void)downloadFontWithURL:(NSURL *)URL { - if ([URL isKindOfClass:[NSURL class]]) { - [self.fontDownloader downloadFontWithURL:URL]; - } -} - -- (void)downloadFontWithURLString:(NSString *)URLString { - [self downloadFontWithURL:[NSURL URLWithString:URLString]]; -} - -- (void)deleteFontWithURL:(NSURL *)URL completeBlock:(void(^)())completeBlock { - if ([URL isKindOfClass:[NSURL class]]) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self.fontCache cleanCachedFileWithWebURL:URL]; - dispatch_async(dispatch_get_main_queue(), ^{ - if (completeBlock) { - completeBlock(); - } - }); - }); - } -} - -- (void)deleteFontWithURLString:(NSString *)URLString completeBlock:(void(^)())completeBlock { - [self deleteFontWithURL:[NSURL URLWithString:URLString] completeBlock:completeBlock]; -} - -#pragma mark - Notification - -- (void)changeModelStatus:(NSNotification *)notif { - FYFontModel *downloadedModel = [notif.userInfo objectForKey:FYNewFontDownloadNotificationKey]; - for (FYFontModel *model in self.fontModelArray) { - if ([model.URL isEqual:downloadedModel.URL]) { - model.status = FYFontModelDownloadStatusDownloaded; - break; - } - } -} - -#pragma mark - Accessor - -- (void)setFontURLStringArray:(NSArray *)fontURLStringArray { - _fontURLStringArray = fontURLStringArray; - - NSMutableArray *fontModelArray = [NSMutableArray array]; - [fontURLStringArray enumerateObjectsUsingBlock:^(NSString * _Nonnull URLString, NSUInteger idx, BOOL * _Nonnull stop) { - if ([URLString isKindOfClass:[NSString class]]) { - NSURL *URL = [NSURL URLWithString:URLString]; - if ([URL isKindOfClass:[NSURL class]]) { - FYFontModel *model = [FYFontModel modelWithURL:URL - status:FYFontModelDownloadStatusToBeDownloaded - downloadProgress:0.0f]; - NSString *cachePath = [self.fontCache cachedFilePathWithWebURL:URL]; - if (cachePath) { - model.status = FYFontModelDownloadStatusDownloaded; - } - [fontModelArray addObject:model]; - } - } - }]; - _fontModelArray = [fontModelArray copy]; -} - -- (NSMutableDictionary *)postScriptNames { - if (!_postScriptNames) { - _postScriptNames = [NSMutableDictionary dictionary]; - } - return _postScriptNames; -} - -@end - diff --git a/Fonty-Demo/Fonty/FYFontModel.h b/Fonty-Demo/Fonty/FYFontModel.h deleted file mode 100644 index faa3f66..0000000 --- a/Fonty-Demo/Fonty/FYFontModel.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// FYFontModel.h -// Fonty -// -// Created by 颜为晨 on 9/8/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import - - -typedef NS_ENUM(NSUInteger, FYFontModelDownloadStatus) { - FYFontModelDownloadStatusToBeDownloaded, - FYFontModelDownloadStatusDownloading, - FYFontModelDownloadStatusDownloaded, - FYFontModelDownloadStatusDeleting -}; - -@interface FYFontModel : NSObject - -@property (nonatomic, copy) NSURL *URL; -@property (nonatomic, assign) FYFontModelDownloadStatus status; -@property (nonatomic, assign) float downloadProgress; -@property (nonatomic, copy) NSString *postScriptName; - -+ (instancetype)modelWithURL:(NSURL *)URL - status:(FYFontModelDownloadStatus)status - downloadProgress:(float)downloadProgress; - -@end diff --git a/Fonty-Demo/Fonty/FYFontModel.m b/Fonty-Demo/Fonty/FYFontModel.m deleted file mode 100644 index 2dbcf71..0000000 --- a/Fonty-Demo/Fonty/FYFontModel.m +++ /dev/null @@ -1,24 +0,0 @@ -// -// FYFontModel.m -// Fonty -// -// Created by 颜为晨 on 9/8/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import "FYFontModel.h" - -@implementation FYFontModel - -+ (instancetype)modelWithURL:(NSURL *)URL - status:(FYFontModelDownloadStatus)status - downloadProgress:(float)downloadProgress { - FYFontModel *model = [[FYFontModel alloc] init]; - model.URL = URL; - model.status = status; - model.downloadProgress = downloadProgress; - model.postScriptName = @""; - return model; -} - -@end diff --git a/Fonty-Demo/Fonty/FYFontRegister.h b/Fonty-Demo/Fonty/FYFontRegister.h deleted file mode 100644 index dd10b38..0000000 --- a/Fonty-Demo/Fonty/FYFontRegister.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// FYFontRegister.h -// Fonty -// -// Created by 颜为晨 on 9/9/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import - -@interface FYFontRegister : NSObject - -+ (instancetype)sharedRegister; - -- (NSString *)registerFontWithPath:(NSString *)path completeBlock:(void(^)(NSString *))completeBlock; - -@end diff --git a/Fonty-Demo/Fonty/FYFontRegister.m b/Fonty-Demo/Fonty/FYFontRegister.m deleted file mode 100644 index a7bdc2a..0000000 --- a/Fonty-Demo/Fonty/FYFontRegister.m +++ /dev/null @@ -1,39 +0,0 @@ -// -// FYFontRegister.m -// Fonty -// -// Created by 颜为晨 on 9/9/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#import -#import "FYFontRegister.h" - -@implementation FYFontRegister - -+ (instancetype)sharedRegister { - static id instance; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - instance = [self new]; - }); - return instance; -} - -- (NSString *)registerFontWithPath:(NSString *)path completeBlock:(void(^)(NSString *))completeBlock { - NSString *postScriptName = nil; - NSURL *fontUrl = [NSURL fileURLWithPath:path]; - CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl); - CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider); - if (fontRef) { - CTFontManagerRegisterGraphicsFont(fontRef, NULL); - postScriptName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef)); - if (completeBlock) { - completeBlock(postScriptName); - } - } - CGFontRelease(fontRef); - return postScriptName; -} - -@end diff --git a/Fonty-Demo/Fonty/FYHeader.h b/Fonty-Demo/Fonty/FYHeader.h deleted file mode 100644 index a1f146b..0000000 --- a/Fonty-Demo/Fonty/FYHeader.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// FYHeader.h -// Fonty -// -// Created by 颜为晨 on 9/8/16. -// Copyright © 2016 颜为晨. All rights reserved. -// - -#ifndef FYHeader_h -#define FYHeader_h - -#import "FYFontManager.h" -#import "FYFontCache.h" -#import "FYFontDownloader.h" -#import "FYFontRegister.h" -#import "FYFontModel.h" - -#endif /* FYHeader_h */ diff --git a/Fonty-Demo/Fonty/UIFont+FY_Fonty.h b/Fonty-Demo/Fonty/UIFont+FY_Fonty.h deleted file mode 100644 index fb31b3b..0000000 --- a/Fonty-Demo/Fonty/UIFont+FY_Fonty.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UIFont+FY_Fonty.h -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import -#import "FYFontManager.h" - -@interface UIFont (FY_Fonty) -+ (UIFont *)fy_mainFontOfSize:(CGFloat)size; -+ (UIFont *)fy_fontWithURL:(NSURL *)URL size:(CGFloat)size; -+ (UIFont *)fy_fontWithURLString:(NSString *)URLString size:(CGFloat)size; - -@end diff --git a/Fonty-Demo/Fonty/UIFont+FY_Fonty.m b/Fonty-Demo/Fonty/UIFont+FY_Fonty.m deleted file mode 100644 index 15eeb75..0000000 --- a/Fonty-Demo/Fonty/UIFont+FY_Fonty.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// UIFont+FY_Fonty.m -// Fonty -// -// Created by 颜为晨 on 16/7/2. -// Copyright © 2016年 颜为晨. All rights reserved. -// - -#import "UIFont+FY_Fonty.h" - -@implementation UIFont (FY_Fonty) - -+ (UIFont *)fy_mainFontOfSize:(CGFloat)size { - return [[FYFontManager sharedManager] mainFontOfSize:size]; -} - -+ (UIFont *)fy_fontWithURL:(NSURL *)URL size:(CGFloat)size { - return [[FYFontManager sharedManager] fontWithURL:URL size:size]; -} - -+ (UIFont *)fy_fontWithURLString:(NSString *)URLString size:(CGFloat)size { - return [[FYFontManager sharedManager] fontWithURLString:URLString size:size]; -} - -@end diff --git a/Fonty-Demo/Fonty-Demo/Info.plist b/Fonty-Demo/Info.plist similarity index 93% rename from Fonty-Demo/Fonty-Demo/Info.plist rename to Fonty-Demo/Info.plist index 40c6215..e09b2be 100644 --- a/Fonty-Demo/Fonty-Demo/Info.plist +++ b/Fonty-Demo/Info.plist @@ -2,6 +2,11 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/Fonty-Demo/Fonty-Demo/ViewController.h b/Fonty-Demo/ViewController.h similarity index 100% rename from Fonty-Demo/Fonty-Demo/ViewController.h rename to Fonty-Demo/ViewController.h diff --git a/Fonty-Demo/ViewController.m b/Fonty-Demo/ViewController.m new file mode 100644 index 0000000..fad8ff7 --- /dev/null +++ b/Fonty-Demo/ViewController.m @@ -0,0 +1,54 @@ +// +// ViewController.m +// Fonty-Demo +// +// Created by 颜为晨 on 9/12/16. +// Copyright © 2016 s2mh. All rights reserved. +// + +#import "ViewController.h" +#import "FYSelectFontViewController.h" +#import "FYHeader.h" +#import "UIFont+FY_Fonty.h" + +@interface ViewController () + +@property (nonatomic, weak) UILabel *label; +@property (nonatomic, strong) UIProgressView *progressView; + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [[FYFontManager sharedManager] setFontURLStringArray:@[@"http://115.28.28.235:8080/xx.ttf", + @"http://www.zhaozi.cn/e/enews/?enews=DownSoft&classid=297&id=22785&pathid=0&pass=6a9c20be7abab75c8128ada2c271b041&p=:::"]]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 50.0f, 300.0f, 50.0f)]; + label.text = @"汉字"; + [self.view addSubview:label]; + self.label = label; + + UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem]; + button1.tag = 1; + button1.frame = CGRectMake(10.0f, 100.0f, 300.0f, 20.0f); + [button1 setTitle:@"Fonty" forState:UIControlStateNormal]; + [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:button1]; +} + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + [self.label setFont:[UIFont fy_mainFontOfSize:20.0f]]; +} + +- (void)buttonAction:(UIButton *)sender { + FYSelectFontViewController *vc = [[FYSelectFontViewController alloc] init]; + UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc]; + [self presentViewController:nc animated:YES completion:nil]; +} + +@end diff --git a/Fonty-Demo/Fonty-Demo/main.m b/Fonty-Demo/main.m similarity index 100% rename from Fonty-Demo/Fonty-Demo/main.m rename to Fonty-Demo/main.m diff --git a/Fonty/FYFontManager.h b/Fonty/FYFontManager.h index 2ec37f2..7f41779 100644 --- a/Fonty/FYFontManager.h +++ b/Fonty/FYFontManager.h @@ -11,8 +11,6 @@ @class FYFontModel; -extern const NSInteger FYUsingSystemFontIndex; - @interface FYFontManager : NSObject + (instancetype)sharedManager; diff --git a/Fonty/FYFontManager.m b/Fonty/FYFontManager.m index 1245438..261a981 100644 --- a/Fonty/FYFontManager.m +++ b/Fonty/FYFontManager.m @@ -12,8 +12,6 @@ #import "FYFontDownloader.h" #import "FYFontModel.h" -const NSInteger FYUsingSystemFontIndex = NSIntegerMin; - @interface FYFontManager () @property (nonatomic, strong) FYFontCache *fontCache; @@ -44,7 +42,7 @@ - (instancetype)init _fontCache = [FYFontCache sharedFontCache]; _fontDownloader = [FYFontDownloader sharedDownloader]; _fontRegister = [FYFontRegister sharedRegister]; - _mainFontIndex = FYUsingSystemFontIndex; + _mainFontIndex = 0; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeModelStatus:) name:FYNewFontDownloadNotification @@ -53,6 +51,11 @@ - (instancetype)init return self; } +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + #pragma mark - Public - (UIFont *)fontWithURL:(NSURL *)URL size:(CGFloat)size { @@ -146,6 +149,12 @@ - (void)setFontURLStringArray:(NSArray *)fontURLStringArray { _fontURLStringArray = fontURLStringArray; NSMutableArray *fontModelArray = [NSMutableArray array]; + + // stand for system default font + [fontModelArray addObject:[FYFontModel modelWithURL:nil + status:FYFontModelDownloadStatusDownloaded + downloadProgress:0.0f]]; + [fontURLStringArray enumerateObjectsUsingBlock:^(NSString * _Nonnull URLString, NSUInteger idx, BOOL * _Nonnull stop) { if ([URLString isKindOfClass:[NSString class]]) { NSURL *URL = [NSURL URLWithString:URLString]; diff --git a/Fonty/FYFontModel.m b/Fonty/FYFontModel.m index 2dbcf71..8982512 100644 --- a/Fonty/FYFontModel.m +++ b/Fonty/FYFontModel.m @@ -10,6 +10,15 @@ @implementation FYFontModel +- (NSString *)description +{ + if (self.URL) { + return self.URL.absoluteString; + } else { + return @"system default font"; + } +} + + (instancetype)modelWithURL:(NSURL *)URL status:(FYFontModelDownloadStatus)status downloadProgress:(float)downloadProgress {