From d2c9cbae802bd7f88fa664cbdd668b2114bb3af1 Mon Sep 17 00:00:00 2001 From: Max Campolo Date: Tue, 8 Dec 2015 16:07:28 -0500 Subject: [PATCH 1/3] Add IonButton.swift to source files --- .../project.pbxproj | 18 ++++++- .../Base.lproj/Main_iPad.storyboard | 16 ++++-- .../Base.lproj/Main_iPhone.storyboard | 35 +++++++++---- .../AppIcon.appiconset/Contents.json | 15 ++++++ ionicons.podspec | 2 +- ionicons/Example-ionicons-Bridging-Header.h | 6 +++ ionicons/IonButton.swift | 52 +++++++++++++++++++ 7 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 ionicons/Example-ionicons-Bridging-Header.h create mode 100644 ionicons/IonButton.swift diff --git a/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj b/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj index e4f022d..2e8a6b6 100644 --- a/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj +++ b/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 307938F01C1728E50034CC99 /* IonButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307938EF1C1728E50034CC99 /* IonButton.swift */; }; 554206721821715F005A3D9E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554206711821715F005A3D9E /* Foundation.framework */; }; 5542067418217160005A3D9E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554206731821715F005A3D9E /* CoreGraphics.framework */; }; 5542067618217160005A3D9E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5542067518217160005A3D9E /* UIKit.framework */; }; @@ -25,7 +26,7 @@ 554206B018217179005A3D9E /* IonIcons.m in Sources */ = {isa = PBXBuildFile; fileRef = 554206AC18217179005A3D9E /* IonIcons.m */; }; 554206B218217179005A3D9E /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 554206AE18217179005A3D9E /* LICENSE */; }; 55E4275C1AE2DB6A00EF1098 /* FontInspector.m in Sources */ = {isa = PBXBuildFile; fileRef = 55E4275B1AE2DB6A00EF1098 /* FontInspector.m */; }; - 55FFA09A1BDBFDD90004F457 /* ionicons.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 55FFA0991BDBFDD90004F457 /* ionicons.bundle */; settings = {ASSET_TAGS = (); }; }; + 55FFA09A1BDBFDD90004F457 /* ionicons.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 55FFA0991BDBFDD90004F457 /* ionicons.bundle */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -39,6 +40,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 307938EE1C1728E50034CC99 /* Example-ionicons-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example-ionicons-Bridging-Header.h"; sourceTree = ""; }; + 307938EF1C1728E50034CC99 /* IonButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IonButton.swift; sourceTree = ""; }; 5542066E1821715F005A3D9E /* Example-ionicons.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-ionicons.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 554206711821715F005A3D9E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 554206731821715F005A3D9E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -182,7 +185,9 @@ 554206AE18217179005A3D9E /* LICENSE */, 55E4275A1AE2DB6A00EF1098 /* FontInspector.h */, 55E4275B1AE2DB6A00EF1098 /* FontInspector.m */, + 307938EF1C1728E50034CC99 /* IonButton.swift */, 55FFA0991BDBFDD90004F457 /* ionicons.bundle */, + 307938EE1C1728E50034CC99 /* Example-ionicons-Bridging-Header.h */, ); name = ionicons; path = ../../ionicons; @@ -233,6 +238,7 @@ 554206661821715F005A3D9E /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0500; ORGANIZATIONNAME = TapTemplate; TargetAttributes = { @@ -305,6 +311,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 307938F01C1728E50034CC99 /* IonButton.swift in Sources */, 5542068B18217160005A3D9E /* ViewController.m in Sources */, 5542068218217160005A3D9E /* AppDelegate.m in Sources */, 55E4275C1AE2DB6A00EF1098 /* FontInspector.m in Sources */, @@ -446,10 +453,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Example-ionicons/Example-ionicons-Prefix.pch"; INFOPLIST_FILE = "Example-ionicons/Example-ionicons-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "../ionicons/Example-ionicons-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -459,10 +471,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Example-ionicons/Example-ionicons-Prefix.pch"; INFOPLIST_FILE = "Example-ionicons/Example-ionicons-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "../ionicons/Example-ionicons-Bridging-Header.h"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPad.storyboard b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPad.storyboard index a185e8a..e517ab5 100644 --- a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPad.storyboard +++ b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPad.storyboard @@ -1,16 +1,22 @@ - + - + + - + + + + + - + + @@ -23,4 +29,4 @@ - \ No newline at end of file + diff --git a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard index b99208b..fae3d60 100644 --- a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard +++ b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard @@ -1,26 +1,43 @@ - + - + + + + + Ionicons + + - + + + + + + + + + + - - - - - - \ No newline at end of file + diff --git a/Example-ionicons/Example-ionicons/Images.xcassets/AppIcon.appiconset/Contents.json b/Example-ionicons/Example-ionicons/Images.xcassets/AppIcon.appiconset/Contents.json index 91bf9c1..36d2c80 100644 --- a/Example-ionicons/Example-ionicons/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example-ionicons/Example-ionicons/Images.xcassets/AppIcon.appiconset/Contents.json @@ -5,16 +5,31 @@ "size" : "29x29", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, { "idiom" : "ipad", "size" : "29x29", diff --git a/ionicons.podspec b/ionicons.podspec index 75e2d2c..7d4d303 100644 --- a/ionicons.podspec +++ b/ionicons.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.author = { "David Sweetman" => "david@davidsweetman.com" } s.source = { :git => "https://github.com/sweetmandm/ionicons-iOS.git", :tag => "2.0.3" } s.platform = :ios, '5.0' - s.source_files = 'ionicons/**/*.{h,m}' + s.source_files = 'ionicons/**/*.{h,m,.swift}' s.resources = "ionicons/ionicons.bundle" s.requires_arc = true end diff --git a/ionicons/Example-ionicons-Bridging-Header.h b/ionicons/Example-ionicons-Bridging-Header.h new file mode 100644 index 0000000..c1fec63 --- /dev/null +++ b/ionicons/Example-ionicons-Bridging-Header.h @@ -0,0 +1,6 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "ionicons.h" +#import "ionicons-codes.h" \ No newline at end of file diff --git a/ionicons/IonButton.swift b/ionicons/IonButton.swift new file mode 100644 index 0000000..39e188f --- /dev/null +++ b/ionicons/IonButton.swift @@ -0,0 +1,52 @@ +// +// IonButton.swift +// Example-ionicons +// +// Created by Max Campolo on 12/8/15. +// Copyright © 2015 TapTemplate. All rights reserved. +// + +import UIKit + +@IBDesignable +class IonButton: UIButton { + + /* + // Only override drawRect: if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func drawRect(rect: CGRect) { + // Drawing code + } + */ + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + // Other stuff + } + + override init(frame: CGRect) { + super.init(frame: frame) + } + + @IBInspectable var ionIconName: String { + get { + return self.currentBackgroundImage!.description + } + set { + self.setBackgroundImage(IonIcons.imageWithIcon(self.convertToUnicode(newValue), size: self.frame.size.width, color: .blackColor()), forState:UIControlState.Normal) + } + } + + func convertToUnicode(hexString: String) -> String? { + var result: String? + let scanner = NSScanner(string: hexString) + var unicodeInt = UInt32() + if scanner.scanHexInt(&unicodeInt) { + if let unicodeString: NSString = NSString(bytes: &unicodeInt, length: 4, encoding: NSUTF32LittleEndianStringEncoding) { + result = unicodeString as String + } + } + return result + } + +} From ac953ce2b325428e21962fb1ab25f842d0e74bf6 Mon Sep 17 00:00:00 2001 From: Max Campolo Date: Tue, 8 Dec 2015 16:14:07 -0500 Subject: [PATCH 2/3] Fixed swift extension --- ionicons.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ionicons.podspec b/ionicons.podspec index 7d4d303..dbd91c9 100644 --- a/ionicons.podspec +++ b/ionicons.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.author = { "David Sweetman" => "david@davidsweetman.com" } s.source = { :git => "https://github.com/sweetmandm/ionicons-iOS.git", :tag => "2.0.3" } s.platform = :ios, '5.0' - s.source_files = 'ionicons/**/*.{h,m,.swift}' + s.source_files = 'ionicons/**/*.{h,m,swift}' s.resources = "ionicons/ionicons.bundle" s.requires_arc = true end From 78913ab462854bf994699bb10874902f6246b836 Mon Sep 17 00:00:00 2001 From: Max Campolo Date: Tue, 8 Dec 2015 16:57:25 -0500 Subject: [PATCH 3/3] Added IonImageView, moved example project bridging header --- .../project.pbxproj | 10 ++-- Example-ionicons/Example-ionicons/.DS_Store | Bin 6148 -> 8196 bytes .../Base.lproj/Main_iPhone.storyboard | 20 +++---- .../Example-ionicons-Bridging-Header.h | 0 ionicons/IonButton.swift | 17 ++++-- ionicons/IonImageView.swift | 51 ++++++++++++++++++ 6 files changed, 82 insertions(+), 16 deletions(-) rename {ionicons => Example-ionicons/Example-ionicons}/Example-ionicons-Bridging-Header.h (100%) create mode 100644 ionicons/IonImageView.swift diff --git a/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj b/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj index 2e8a6b6..16bb339 100644 --- a/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj +++ b/Example-ionicons/Example-ionicons.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 307938F01C1728E50034CC99 /* IonButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307938EF1C1728E50034CC99 /* IonButton.swift */; }; + 30ACE8091C1780D8009EA9E6 /* IonImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30ACE8081C1780D8009EA9E6 /* IonImageView.swift */; }; 554206721821715F005A3D9E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554206711821715F005A3D9E /* Foundation.framework */; }; 5542067418217160005A3D9E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554206731821715F005A3D9E /* CoreGraphics.framework */; }; 5542067618217160005A3D9E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5542067518217160005A3D9E /* UIKit.framework */; }; @@ -42,6 +43,7 @@ /* Begin PBXFileReference section */ 307938EE1C1728E50034CC99 /* Example-ionicons-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example-ionicons-Bridging-Header.h"; sourceTree = ""; }; 307938EF1C1728E50034CC99 /* IonButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IonButton.swift; sourceTree = ""; }; + 30ACE8081C1780D8009EA9E6 /* IonImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IonImageView.swift; sourceTree = ""; }; 5542066E1821715F005A3D9E /* Example-ionicons.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-ionicons.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 554206711821715F005A3D9E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 554206731821715F005A3D9E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -132,6 +134,7 @@ isa = PBXGroup; children = ( 644532D81BAB270E00DC25F0 /* README.md */, + 307938EE1C1728E50034CC99 /* Example-ionicons-Bridging-Header.h */, 554206A918217179005A3D9E /* ionicons */, 5542068018217160005A3D9E /* AppDelegate.h */, 5542068118217160005A3D9E /* AppDelegate.m */, @@ -186,8 +189,8 @@ 55E4275A1AE2DB6A00EF1098 /* FontInspector.h */, 55E4275B1AE2DB6A00EF1098 /* FontInspector.m */, 307938EF1C1728E50034CC99 /* IonButton.swift */, + 30ACE8081C1780D8009EA9E6 /* IonImageView.swift */, 55FFA0991BDBFDD90004F457 /* ionicons.bundle */, - 307938EE1C1728E50034CC99 /* Example-ionicons-Bridging-Header.h */, ); name = ionicons; path = ../../ionicons; @@ -317,6 +320,7 @@ 55E4275C1AE2DB6A00EF1098 /* FontInspector.m in Sources */, 5542067E18217160005A3D9E /* main.m in Sources */, 554206B018217179005A3D9E /* IonIcons.m in Sources */, + 30ACE8091C1780D8009EA9E6 /* IonImageView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -460,7 +464,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "../ionicons/Example-ionicons-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = "../Example-ionicons/Example-ionicons/Example-ionicons-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; WRAPPER_EXTENSION = app; }; @@ -478,7 +482,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "../ionicons/Example-ionicons-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = "../Example-ionicons/Example-ionicons/Example-ionicons-Bridging-Header.h"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/Example-ionicons/Example-ionicons/.DS_Store b/Example-ionicons/Example-ionicons/.DS_Store index 048f053bca518ace5cecd149b73a8a887e163122..4c0997b2a3b07874bf36a0d84500d2a95d0edc82 100644 GIT binary patch literal 8196 zcmeHM!EVz)5PeH46oCpoR^noD;zBCK515c5A|XIj?U}?e!N{$n*aeRM3_gkv;BVl~ z?25*ATG}eAA~757PC7epXZGzl)@%W|!P)c~um_;WE^_xihZRlcrFYt$pm{*)hzC;S z>@$o}b*xQc3>X8(fH7bU7z3NY0N>ftdKbL+{j80~fHCl2G9bSX5xdAZ$l6Q&>ENIx z0OdB-+W4JyfMTK`;~;A<70NYz_22^3g%ZPgIOiiVr;LNFz4UN64~Gk$U8qo;dM7SY zbGX<`8;t>Dpv!>N?mKvaIX}Zj{hp$a&!fCZCV4TTl{{Fl*q{8?#&4G)Pg=;IE#y56 zcuP>yW1n{hb1YEcOB3Thv@ktdpI&1Bt7ZQf2l!4eCtP3dC7vRqms5_3%95G^J!hEm z&LZQ?jGEW998;5Wro({5+?4jT;3Tow? zzOu_-bJ_?i74_ZSWq60f6*K$vw64hChRD~l9^-m+g;N`G$Dg?SzMgDGuBvA4Xr}&H zI;X3w`kp7Aa@~xa%gRY7|0Ro;SAB?)p3#iBk{EwhrJi7gvKf=)&UMh!GRY@JkrRcx z>PAwukJh8*B<+`j+Ql)qkm4I&YMNKvmZXk60xMElsA{D2zwj;pASvf~d;iOESu+MU zpMfnO;-1w12N&P}Z~jIsLSw)fxG@86dw4h;5FTpl&O%aaN9-TjrHNhbr9wDpIZmnN fIOX4e81j2WQ^CYR)?QM>W)}fUgAK;OtupWjKL!u# delta 141 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGqg=C6q~50D9Q+A12Ir6m7$nHkD-DgnIUmv zp*kbuWH(_Yj+El$oTU8xoQ;Kn?2FksI0TtNnt|%MfrKj%w{0x^&ODi4Mwb(0(g7f5 Vm~6u%&BFw-3uHaR=6IeN%m9Qx7hC`U diff --git a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard index fae3d60..e7f1ac4 100644 --- a/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard +++ b/Example-ionicons/Example-ionicons/Base.lproj/Main_iPhone.storyboard @@ -4,11 +4,6 @@ - - - Ionicons - - @@ -22,14 +17,21 @@ - + + + + + + + diff --git a/ionicons/Example-ionicons-Bridging-Header.h b/Example-ionicons/Example-ionicons/Example-ionicons-Bridging-Header.h similarity index 100% rename from ionicons/Example-ionicons-Bridging-Header.h rename to Example-ionicons/Example-ionicons/Example-ionicons-Bridging-Header.h diff --git a/ionicons/IonButton.swift b/ionicons/IonButton.swift index 39e188f..099f8a0 100644 --- a/ionicons/IonButton.swift +++ b/ionicons/IonButton.swift @@ -3,7 +3,7 @@ // Example-ionicons // // Created by Max Campolo on 12/8/15. -// Copyright © 2015 TapTemplate. All rights reserved. +// Copyright © 2015 Max Campolo. All rights reserved. // import UIKit @@ -28,12 +28,21 @@ class IonButton: UIButton { super.init(frame: frame) } - @IBInspectable var ionIconName: String { + @IBInspectable var ionIconBackgroundImage: String? { get { - return self.currentBackgroundImage!.description + return self.currentBackgroundImage?.description } set { - self.setBackgroundImage(IonIcons.imageWithIcon(self.convertToUnicode(newValue), size: self.frame.size.width, color: .blackColor()), forState:UIControlState.Normal) + self.setBackgroundImage(IonIcons.imageWithIcon(self.convertToUnicode(newValue!), size: self.frame.size.width, color: .blackColor()).imageWithRenderingMode(.AlwaysTemplate), forState:UIControlState.Normal) + } + } + + @IBInspectable var ionIconImage: String? { + get { + return self.currentImage?.description + } + set { + self.setImage(IonIcons.imageWithIcon(self.convertToUnicode(newValue!), size: self.frame.size.width, color: .blackColor()).imageWithRenderingMode(.AlwaysTemplate), forState: .Normal) } } diff --git a/ionicons/IonImageView.swift b/ionicons/IonImageView.swift new file mode 100644 index 0000000..2ef0033 --- /dev/null +++ b/ionicons/IonImageView.swift @@ -0,0 +1,51 @@ +// +// IonImageView.swift +// Example-ionicons +// +// Created by Max Campolo on 12/8/15. +// Copyright © 2015 Max Campolo. All rights reserved. +// + +import UIKit + +@IBDesignable +class IonImageView: UIImageView { + + /* + // Only override drawRect: if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func drawRect(rect: CGRect) { + // Drawing code + } + */ + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + // Other stuff + } + + override init(frame: CGRect) { + super.init(frame: frame) + } + + @IBInspectable var ionIconImage: String? { + get { + return self.image?.description + } + set { + self.image = IonIcons.imageWithIcon(self.convertToUnicode(newValue!), size: self.frame.size.width, color: .blackColor()).imageWithRenderingMode(.AlwaysTemplate) + } + } + + func convertToUnicode(hexString: String) -> String? { + var result: String? + let scanner = NSScanner(string: hexString) + var unicodeInt = UInt32() + if scanner.scanHexInt(&unicodeInt) { + if let unicodeString: NSString = NSString(bytes: &unicodeInt, length: 4, encoding: NSUTF32LittleEndianStringEncoding) { + result = unicodeString as String + } + } + return result + } +}