diff --git a/InitialsImageView.podspec b/InitialsImageView.podspec new file mode 100644 index 0000000..c1e3008 --- /dev/null +++ b/InitialsImageView.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = "InitialsImageView" + s.version = "0.1.0" + s.summary = "A simple UIImageView extension for using initials as a profile image, written in swift" + s.description = "An easy, helpful UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color." + s.homepage = "https://github.com/bachonk/InitialsImageView" + s.screenshots = "http://i.imgur.com/xSBjVQ7.png" + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { "Tom Bachant" => "tom@dashride.com" } + s.platform = :ios, '8.0' + s.source = { :git => "https://github.com/bachonk/InitialsImageView.git", + :tag => '0.1.0' } + s.source_files = 'InitialsImageView.swift' + s.requires_arc = true +end diff --git a/InitialsImageView.swift b/InitialsImageView.swift new file mode 100644 index 0000000..2bc0f58 --- /dev/null +++ b/InitialsImageView.swift @@ -0,0 +1,136 @@ +// +// InitialsImageView.swift +// +// +// Created by Tom Bachant on 1/28/17. +// +// + +import UIKit + +let kFontResizingProportion: CGFloat = 0.4 +let kColorMinComponent: Int = 30 +let kColorMaxComponent: Int = 214 + +extension UIImageView { + + public func setImageForName(string: String, backgroundColor: UIColor?, circular: Bool, textAttributes: [String: AnyObject]?) { + + let initials: String = initialsFromString(string: string) + let color: UIColor = (backgroundColor != nil) ? backgroundColor! : randomColor() + let attributes: [String: AnyObject] = (textAttributes != nil) ? textAttributes! : [ + NSFontAttributeName: self.fontForFontName(name: nil), + NSForegroundColorAttributeName: UIColor.white + ] + + self.image = imageSnapshot(text: initials, backgroundColor: color, circular: circular, textAttributes: attributes) + } + + private func fontForFontName(name: String?) -> UIFont { + + let fontSize = self.bounds.width * kFontResizingProportion; + if name != nil { + return UIFont(name: name!, size: fontSize)! + } + else { + return UIFont.systemFont(ofSize: fontSize) + } + + } + + private func imageSnapshot(text imageText: String, backgroundColor: UIColor, circular: Bool, textAttributes: [String : AnyObject]) -> UIImage { + + let scale: CGFloat = UIScreen.main.scale + + var size: CGSize = self.bounds.size + if (self.contentMode == .scaleToFill || + self.contentMode == .scaleAspectFill || + self.contentMode == .scaleAspectFit || + self.contentMode == .redraw) { + + size.width = (size.width * scale) / scale + size.height = (size.height * scale) / scale + } + + UIGraphicsBeginImageContextWithOptions(size, false, scale) + + let context: CGContext = UIGraphicsGetCurrentContext()! + + if circular { + // Clip context to a circle + let path: CGPath = CGPath(ellipseIn: self.bounds, transform: nil) + context.addPath(path) + context.clip() + } + + // Fill background of context + context.setFillColor(backgroundColor.cgColor) + context.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height)) + + // Draw text in the context + let textSize: CGSize = imageText.size(attributes: textAttributes) + let bounds: CGRect = self.bounds + + imageText.draw(in: CGRect(x: bounds.midX - textSize.width / 2, + y: bounds.midY - textSize.height / 2, + width: textSize.width, + height: textSize.height), + withAttributes: textAttributes) + + let snapshot: UIImage = UIGraphicsGetImageFromCurrentImageContext()!; + UIGraphicsEndImageContext(); + + return snapshot; + } +} + +private func initialsFromString(string: String) -> String { + + var displayString: String = "" + var words: [String] = string.components(separatedBy: .whitespacesAndNewlines) + + // Get first letter of the first and last word + if words.count > 0 { + let firstWord: String = words.first! + if firstWord.characters.count > 0 { + // Get character range to handle emoji (emojis consist of 2 characters in sequence) + let range: Range = firstWord.startIndex..= 2 { + var lastWord: String = words.last! + + while lastWord.characters.count == 0 && words.count >= 2 { + words.removeLast() + lastWord = words.last! + } + + if words.count > 1 { + // Get character range to handle emoji (emojis consist of 2 characters in sequence) + let range: Range = lastWord.startIndex.. Int { + let limit = kColorMaxComponent - kColorMinComponent + + return kColorMinComponent + Int(arc4random_uniform(UInt32(limit))) +} + +private func randomColor() -> UIColor { + let red = CGFloat(randomColorComponent()) / 255.0 + let green = CGFloat(randomColorComponent()) / 255.0 + let blue = CGFloat(randomColorComponent()) / 255.0 + + return UIColor(red: red, green: green, blue: blue, alpha: 1.0) +} diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.pbxproj b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.pbxproj new file mode 100644 index 0000000..63b313f --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.pbxproj @@ -0,0 +1,324 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + C874E1AC1E871A33003BC36D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C874E1A41E871A33003BC36D /* AppDelegate.swift */; }; + C874E1AD1E871A33003BC36D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C874E1A51E871A33003BC36D /* Assets.xcassets */; }; + C874E1AE1E871A33003BC36D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C874E1A61E871A33003BC36D /* LaunchScreen.storyboard */; }; + C874E1AF1E871A33003BC36D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C874E1A81E871A33003BC36D /* Main.storyboard */; }; + C874E1B11E871A33003BC36D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C874E1AB1E871A33003BC36D /* ViewController.swift */; }; + C874E1B41E871B01003BC36D /* InitialsImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C874E1B31E871B01003BC36D /* InitialsImageView.swift */; }; + C874E1B51E871D8D003BC36D /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C874E1AA1E871A33003BC36D /* Info.plist */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + C84E0BC51E3D1B42008A5CC4 /* InitialsImageViewSampleSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InitialsImageViewSampleSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C874E1A41E871A33003BC36D /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + C874E1A51E871A33003BC36D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C874E1A71E871A33003BC36D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + C874E1A91E871A33003BC36D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + C874E1AA1E871A33003BC36D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C874E1AB1E871A33003BC36D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C874E1B31E871B01003BC36D /* InitialsImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InitialsImageView.swift; path = ../../InitialsImageView.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C84E0BC21E3D1B42008A5CC4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C84E0BBC1E3D1B42008A5CC4 = { + isa = PBXGroup; + children = ( + C874E1A31E871A33003BC36D /* InitialsImageViewSampleSwift */, + C84E0BC61E3D1B42008A5CC4 /* Products */, + ); + sourceTree = ""; + }; + C84E0BC61E3D1B42008A5CC4 /* Products */ = { + isa = PBXGroup; + children = ( + C84E0BC51E3D1B42008A5CC4 /* InitialsImageViewSampleSwift.app */, + ); + name = Products; + sourceTree = ""; + }; + C874E1A31E871A33003BC36D /* InitialsImageViewSampleSwift */ = { + isa = PBXGroup; + children = ( + C874E1B21E871AEC003BC36D /* Extensions */, + C874E1A41E871A33003BC36D /* AppDelegate.swift */, + C874E1A51E871A33003BC36D /* Assets.xcassets */, + C874E1A61E871A33003BC36D /* LaunchScreen.storyboard */, + C874E1A81E871A33003BC36D /* Main.storyboard */, + C874E1AA1E871A33003BC36D /* Info.plist */, + C874E1AB1E871A33003BC36D /* ViewController.swift */, + ); + path = InitialsImageViewSampleSwift; + sourceTree = ""; + }; + C874E1B21E871AEC003BC36D /* Extensions */ = { + isa = PBXGroup; + children = ( + C874E1B31E871B01003BC36D /* InitialsImageView.swift */, + ); + name = Extensions; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C84E0BC41E3D1B42008A5CC4 /* InitialsImageViewSampleSwift */ = { + isa = PBXNativeTarget; + buildConfigurationList = C84E0BD71E3D1B42008A5CC4 /* Build configuration list for PBXNativeTarget "InitialsImageViewSampleSwift" */; + buildPhases = ( + C84E0BC11E3D1B42008A5CC4 /* Sources */, + C84E0BC21E3D1B42008A5CC4 /* Frameworks */, + C84E0BC31E3D1B42008A5CC4 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = InitialsImageViewSampleSwift; + productName = UIImageViewLettersSampleSwift; + productReference = C84E0BC51E3D1B42008A5CC4 /* InitialsImageViewSampleSwift.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C84E0BBD1E3D1B42008A5CC4 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0820; + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = "Thomas Bachant"; + TargetAttributes = { + C84E0BC41E3D1B42008A5CC4 = { + CreatedOnToolsVersion = 8.2.1; + DevelopmentTeam = BRX3VWK6LR; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = C84E0BC01E3D1B42008A5CC4 /* Build configuration list for PBXProject "InitialsImageViewSampleSwift" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = C84E0BBC1E3D1B42008A5CC4; + productRefGroup = C84E0BC61E3D1B42008A5CC4 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C84E0BC41E3D1B42008A5CC4 /* InitialsImageViewSampleSwift */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + C84E0BC31E3D1B42008A5CC4 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C874E1B51E871D8D003BC36D /* Info.plist in Resources */, + C874E1AF1E871A33003BC36D /* Main.storyboard in Resources */, + C874E1AD1E871A33003BC36D /* Assets.xcassets in Resources */, + C874E1AE1E871A33003BC36D /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + C84E0BC11E3D1B42008A5CC4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C874E1B11E871A33003BC36D /* ViewController.swift in Sources */, + C874E1AC1E871A33003BC36D /* AppDelegate.swift in Sources */, + C874E1B41E871B01003BC36D /* InitialsImageView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + C874E1A61E871A33003BC36D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C874E1A71E871A33003BC36D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; + C874E1A81E871A33003BC36D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C874E1A91E871A33003BC36D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + C84E0BD51E3D1B42008A5CC4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + C84E0BD61E3D1B42008A5CC4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + C84E0BD81E3D1B42008A5CC4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = BRX3VWK6LR; + INFOPLIST_FILE = InitialsImageViewSampleSwift/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.coincidentalcode.InitialsImageViewSampleSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + C84E0BD91E3D1B42008A5CC4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = BRX3VWK6LR; + INFOPLIST_FILE = InitialsImageViewSampleSwift/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.coincidentalcode.InitialsImageViewSampleSwift; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C84E0BC01E3D1B42008A5CC4 /* Build configuration list for PBXProject "InitialsImageViewSampleSwift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C84E0BD51E3D1B42008A5CC4 /* Debug */, + C84E0BD61E3D1B42008A5CC4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C84E0BD71E3D1B42008A5CC4 /* Build configuration list for PBXNativeTarget "InitialsImageViewSampleSwift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C84E0BD81E3D1B42008A5CC4 /* Debug */, + C84E0BD91E3D1B42008A5CC4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C84E0BBD1E3D1B42008A5CC4 /* Project object */; +} diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..cdc4906 --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/AppDelegate.swift b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/AppDelegate.swift new file mode 100644 index 0000000..4a65fe8 --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// UIImageViewLettersSampleSwift +// +// Created by Tom Bachant on 1/28/17. +// Copyright © 2017 Thomas Bachant. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + 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 invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + 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) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + 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) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Assets.xcassets/AppIcon.appiconset/Contents.json b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..1d060ed --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "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" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/LaunchScreen.storyboard b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/Main.storyboard b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/Main.storyboard new file mode 100644 index 0000000..273375f --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Info.plist b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Info.plist new file mode 100644 index 0000000..d052473 --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/ViewController.swift b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/ViewController.swift new file mode 100644 index 0000000..3ca3e44 --- /dev/null +++ b/InitialsImageViewSampleSwift/InitialsImageViewSampleSwift/ViewController.swift @@ -0,0 +1,38 @@ +// +// ViewController.swift +// UIImageViewLettersSampleSwift +// +// Created by Tom Bachant on 1/28/17. +// Copyright © 2017 Thomas Bachant. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + + // Simple example with a random background color + let randomImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY - 80 - 40, width: 80, height: 80)) + self.view.addSubview(randomImage) + + randomImage.setImageForName(string: "Hello World", backgroundColor: nil, circular: true, textAttributes: nil) + + // More specific option with bg color and font specified + let customImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY + 40, width: 80, height: 80)) + self.view.addSubview(customImage) + + customImage.setImageForName(string: "Custom Font", backgroundColor: .blue, circular: true, textAttributes: [NSFontAttributeName: UIFont(name: "AmericanTypewriter-Bold", size: 30)!, NSForegroundColorAttributeName: UIColor.init(white: 1.0, alpha: 0.5)]) + + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + +} +