Skip to content

Commit

Permalink
corresponded to swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tichise committed Sep 22, 2017
1 parent 55a982f commit 3f06792
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 33 deletions.
2 changes: 1 addition & 1 deletion EntypoSymbol.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EntypoSymbol'
s.version = '1.5'
s.version = '1.6'
s.license = 'Creative Commons Attribution 4.0 International (CC BY 4.0)'
s.summary = 'Icon font library for Swift. Currently supports Entypo'
s.homepage = 'https://github.com/tichise/EntypoSymbol'
Expand Down
11 changes: 10 additions & 1 deletion Sample/Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = tichise;
TargetAttributes = {
B09B7E1E1AFF03DF0074ACA7 = {
Expand Down Expand Up @@ -418,8 +418,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -447,6 +449,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -463,8 +466,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -483,6 +488,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -491,6 +498,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = C3D70F8918D2F7AE8ED38EBC /* Pods-Sample.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Sample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -503,6 +511,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 33135A902F0149A25F960560 /* Pods-Sample.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Sample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
12 changes: 6 additions & 6 deletions Sample/Sample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
4 changes: 2 additions & 2 deletions Sample/Sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let symbol:EntypoSymbol = EntypoSymbol(text:EntypoIcon.install, size:25)
let iconImage:UIImage = symbol.imageWithSize(CGSizeMake(25, 25))
let symbol:EntypoSymbol = EntypoSymbol(text:EntypoIcon.install as NSString, size:25)
let iconImage:UIImage = symbol.imageWithSize(size: CGSize(width: 25, height: 25))
self.sampleImageView.image = iconImage

sampleLabelView.font = EntypoFont.fontOfSize(40)
Expand Down
25 changes: 18 additions & 7 deletions Sources/EntypoFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@

import UIKit

public class EntypoFont {
/**
マテリアルデザインアイコンをUIFont形式で呼ぶに使うクラス
*/
public class EntypoFont:NSObject {

public class func fontOfSize(fontSize: CGFloat) -> UIFont {
/**
アイコンをフォント形式で呼び出すのに使うメソッド
- parameter fontSize: フォントサイズ
- returns: UIFont
*/
open class func fontOfSize(_ fontSize: CGFloat) -> UIFont {

struct Static {
static var onceToken : dispatch_once_t = 0

// MARK: - Properties
static var onceToken : Int = 0
}

/// 呼び出すアイコンファイル名
let name = "entypo"
if (UIFont.fontNamesForFamilyName(name).count == 0) {
dispatch_once(&Static.onceToken) {
FontLoader.loadFont(name)
}

// アイコンを呼び出す
if (UIFont.fontNames(forFamilyName: name).count == 0) {
FontLoader.loadFont(name: name)
}

return UIFont(name: name, size: fontSize)!
Expand Down
21 changes: 14 additions & 7 deletions Sources/EntypoSymbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,38 @@ import UIKit
public class EntypoSymbol {

var text:NSString = ""

var mutableTextFontAttributes = [String : AnyObject]()

public init(text:NSString, size:CGFloat) {
self.text = text

self.mutableTextFontAttributes = [String : AnyObject]()
self.mutableTextFontAttributes[NSParagraphStyleAttributeName] = NSMutableParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle
self.mutableTextFontAttributes[NSParagraphStyleAttributeName] = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle

self.mutableTextFontAttributes[NSFontAttributeName] = EntypoFont.fontOfSize(size)
}

public func addAttribute(attributeName:NSObject, value:AnyObject) {
self.mutableTextFontAttributes[attributeName as! String] = value
// MARK: - Method
public func addAttribute(attributeName:String, value:AnyObject) {
self.mutableTextFontAttributes[attributeName] = value
}

/**
// アイコンを画像形式で取得するのに使うメソッド
- parameter size: サイズ
- returns: UIImage
*/
public func imageWithSize(size:CGSize)->UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, 0)

let textRect = CGRectMake(0, 0, size.width, size.height)
self.text.drawInRect(textRect, withAttributes: self.mutableTextFontAttributes)
let textRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
self.text.draw(in: textRect, withAttributes: self.mutableTextFontAttributes)

let image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext()

return image
return image!
}
}
}
18 changes: 9 additions & 9 deletions Sources/FontLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// Created by tichise on 2015/5/7 15/05/07.
// Copyright (c) 2015 tichise. All rights reserved.
//

import UIKit


/**
フォント読み込み用クラス
*/
Expand All @@ -19,20 +19,20 @@ public class FontLoader {
*/
public class func loadFont(name: String) {

let ttfPath = NSBundle(forClass:object_getClass(self)).pathForResource(name, ofType:"ttf")
let ttfPath = Bundle(for:object_getClass(self)).path(forResource: name, ofType:"ttf")

let fileHandle : NSFileHandle = NSFileHandle(forReadingAtPath: ttfPath!)!
let data : NSData = fileHandle.readDataToEndOfFile()
let fileHandle : FileHandle = FileHandle(forReadingAtPath: ttfPath!)!
let data : NSData = fileHandle.readDataToEndOfFile() as NSData

let provider = CGDataProviderCreateWithCFData(data)
let font = CGFontCreateWithDataProvider(provider)!
let provider = CGDataProvider(data: data)
let font = CGFont(provider!)

var error: Unmanaged<CFError>?

if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription: CFStringRef = CFErrorCopyDescription(error!.takeUnretainedValue())
let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
NSException(name: NSInternalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
}
}
}
}

0 comments on commit 3f06792

Please sign in to comment.