├── .github ├── Logo.png ├── demo1.gif └── demo2.gif ├── Example ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── AutoFitLabel.swift ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── FontFit.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── hz6y8w.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── hz6y8w.xcuserdatad │ └── xcschemes │ ├── Example.xcscheme │ └── xcschememanagement.plist ├── FontFit ├── FontFit.h ├── Info.plist ├── TextSizingOption.swift ├── UIFont+FontFit.swift ├── UILabel+FontFit.swift └── UITextView+FontFit.swift ├── LICENSE └── README.md /.github/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joncardasis/FontFit/2ab7230881b40b7e2728c566fbce098865fa5972/.github/Logo.png -------------------------------------------------------------------------------- /.github/demo1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joncardasis/FontFit/2ab7230881b40b7e2728c566fbce098865fa5972/.github/demo1.gif -------------------------------------------------------------------------------- /.github/demo2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joncardasis/FontFit/2ab7230881b40b7e2728c566fbce098865fa5972/.github/demo2.gif -------------------------------------------------------------------------------- /Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/AutoFitLabel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutoFitLabel.swift 3 | // Example 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import FontFit 11 | 12 | @IBDesignable 13 | class AutoFitLabel: UILabel { 14 | 15 | /** 16 | Overrides the font size of the label, scaling text to best fit it's bounds. 17 | */ 18 | @IBInspectable 19 | var adjustsFontToFitContainer: Bool = true { 20 | didSet { updateFontIfNeeded() } 21 | } 22 | 23 | /** 24 | Overrides the font size of the label, scaling text to fit the number of lines provided. 25 | */ 26 | var autosizeFontToNumberOfLines: UInt? { 27 | didSet { updateFontIfNeeded() } 28 | } 29 | 30 | override func layoutSubviews() { 31 | super.layoutSubviews() 32 | updateFontIfNeeded() 33 | } 34 | 35 | private func updateFontIfNeeded() { 36 | if let numberOfLines = autosizeFontToNumberOfLines { 37 | fitText(maxLines: numberOfLines) 38 | } else if adjustsFontToFitContainer { 39 | fitTextToBounds() 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 29 | 30 | 31 | 32 | 47 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 85 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 117 | 126 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var label: AutoFitLabel! 14 | @IBOutlet weak var labelWidthConstraint: NSLayoutConstraint! 15 | @IBOutlet weak var labelHeightConstraint: NSLayoutConstraint! 16 | @IBOutlet weak var preferredLinesLabel: UILabel! 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | styleLabel() 21 | label.text = "That which yields is not always weak." 22 | } 23 | 24 | private func styleLabel() { 25 | label.layer.cornerRadius = 6.0 26 | label.layer.masksToBounds = true 27 | label.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1) 28 | } 29 | 30 | // MARK: - IBActions 31 | 32 | @IBAction func sliderChanged(_ sender: UISlider) { 33 | let preferredNumberOfLines = UInt(sender.value) 34 | 35 | if preferredNumberOfLines == 0 { 36 | label.autosizeFontToNumberOfLines = nil 37 | preferredLinesLabel.text = "N/A" 38 | } else { 39 | label.autosizeFontToNumberOfLines = preferredNumberOfLines 40 | preferredLinesLabel.text = "\(preferredNumberOfLines)" 41 | } 42 | 43 | label.layoutIfNeeded() 44 | } 45 | 46 | @IBAction func shrinkWidth(_ sender: Any) { 47 | labelWidthConstraint.constant -= 10 48 | } 49 | 50 | @IBAction func growWidth(_ sender: Any) { 51 | labelWidthConstraint.constant += 10 52 | } 53 | 54 | @IBAction func shrinkHeight(_ sender: Any) { 55 | labelHeightConstraint.constant -= 10 56 | } 57 | 58 | @IBAction func growHeight(_ sender: Any) { 59 | labelHeightConstraint.constant += 10 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /FontFit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B9398C73227A29D900654C58 /* UITextView+FontFit.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9398C72227A29D900654C58 /* UITextView+FontFit.swift */; }; 11 | B9741FB522739FF200D69DF3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FB422739FF200D69DF3 /* AppDelegate.swift */; }; 12 | B9741FB722739FF200D69DF3 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FB622739FF200D69DF3 /* ViewController.swift */; }; 13 | B9741FBA22739FF200D69DF3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B9741FB822739FF200D69DF3 /* Main.storyboard */; }; 14 | B9741FBC22739FF300D69DF3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B9741FBB22739FF300D69DF3 /* Assets.xcassets */; }; 15 | B9741FBF22739FF300D69DF3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B9741FBD22739FF300D69DF3 /* LaunchScreen.storyboard */; }; 16 | B9741FCF2273A08300D69DF3 /* FontFit.h in Headers */ = {isa = PBXBuildFile; fileRef = B9741FCD2273A08300D69DF3 /* FontFit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17 | B9741FD42273A0A100D69DF3 /* TextSizingOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FD32273A0A100D69DF3 /* TextSizingOption.swift */; }; 18 | B9741FD62273A0C300D69DF3 /* UIFont+FontFit.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FD52273A0C300D69DF3 /* UIFont+FontFit.swift */; }; 19 | B9741FD92273A0F800D69DF3 /* UILabel+FontFit.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FD82273A0F800D69DF3 /* UILabel+FontFit.swift */; }; 20 | B9741FDB2273A17200D69DF3 /* AutoFitLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9741FDA2273A17200D69DF3 /* AutoFitLabel.swift */; }; 21 | B9741FE02273A31C00D69DF3 /* FontFit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9741FCB2273A08300D69DF3 /* FontFit.framework */; }; 22 | B9741FE12273A31C00D69DF3 /* FontFit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B9741FCB2273A08300D69DF3 /* FontFit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | B9741FDC2273A1C100D69DF3 /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = B9741FA922739FF200D69DF3 /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = B9741FCA2273A08300D69DF3; 31 | remoteInfo = FontFit; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXCopyFilesBuildPhase section */ 36 | B9741FE22273A31C00D69DF3 /* Embed Frameworks */ = { 37 | isa = PBXCopyFilesBuildPhase; 38 | buildActionMask = 2147483647; 39 | dstPath = ""; 40 | dstSubfolderSpec = 10; 41 | files = ( 42 | B9741FE12273A31C00D69DF3 /* FontFit.framework in Embed Frameworks */, 43 | ); 44 | name = "Embed Frameworks"; 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXCopyFilesBuildPhase section */ 48 | 49 | /* Begin PBXFileReference section */ 50 | B9398C72227A29D900654C58 /* UITextView+FontFit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+FontFit.swift"; sourceTree = ""; }; 51 | B9741FB122739FF200D69DF3 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | B9741FB422739FF200D69DF3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 53 | B9741FB622739FF200D69DF3 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 54 | B9741FB922739FF200D69DF3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 55 | B9741FBB22739FF300D69DF3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 56 | B9741FBE22739FF300D69DF3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 57 | B9741FC022739FF300D69DF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | B9741FCB2273A08300D69DF3 /* FontFit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FontFit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | B9741FCD2273A08300D69DF3 /* FontFit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontFit.h; sourceTree = ""; }; 60 | B9741FCE2273A08300D69DF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 61 | B9741FD32273A0A100D69DF3 /* TextSizingOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextSizingOption.swift; sourceTree = ""; }; 62 | B9741FD52273A0C300D69DF3 /* UIFont+FontFit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+FontFit.swift"; sourceTree = ""; }; 63 | B9741FD82273A0F800D69DF3 /* UILabel+FontFit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+FontFit.swift"; sourceTree = ""; }; 64 | B9741FDA2273A17200D69DF3 /* AutoFitLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoFitLabel.swift; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | B9741FAE22739FF200D69DF3 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | B9741FE02273A31C00D69DF3 /* FontFit.framework in Frameworks */, 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | B9741FC82273A08300D69DF3 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | B9741FA822739FF200D69DF3 = { 87 | isa = PBXGroup; 88 | children = ( 89 | B9741FB322739FF200D69DF3 /* Example */, 90 | B9741FCC2273A08300D69DF3 /* FontFit */, 91 | B9741FB222739FF200D69DF3 /* Products */, 92 | B9741FDE2273A1D700D69DF3 /* Frameworks */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | B9741FB222739FF200D69DF3 /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | B9741FB122739FF200D69DF3 /* Example.app */, 100 | B9741FCB2273A08300D69DF3 /* FontFit.framework */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | B9741FB322739FF200D69DF3 /* Example */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | B9741FB422739FF200D69DF3 /* AppDelegate.swift */, 109 | B9741FB622739FF200D69DF3 /* ViewController.swift */, 110 | B9741FDA2273A17200D69DF3 /* AutoFitLabel.swift */, 111 | B9741FB822739FF200D69DF3 /* Main.storyboard */, 112 | B9741FBB22739FF300D69DF3 /* Assets.xcassets */, 113 | B9741FBD22739FF300D69DF3 /* LaunchScreen.storyboard */, 114 | B9741FC022739FF300D69DF3 /* Info.plist */, 115 | ); 116 | path = Example; 117 | sourceTree = ""; 118 | }; 119 | B9741FCC2273A08300D69DF3 /* FontFit */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | B9741FD82273A0F800D69DF3 /* UILabel+FontFit.swift */, 123 | B9398C72227A29D900654C58 /* UITextView+FontFit.swift */, 124 | B9741FD52273A0C300D69DF3 /* UIFont+FontFit.swift */, 125 | B9741FCD2273A08300D69DF3 /* FontFit.h */, 126 | B9741FCE2273A08300D69DF3 /* Info.plist */, 127 | B9741FD32273A0A100D69DF3 /* TextSizingOption.swift */, 128 | ); 129 | path = FontFit; 130 | sourceTree = ""; 131 | }; 132 | B9741FDE2273A1D700D69DF3 /* Frameworks */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | ); 136 | name = Frameworks; 137 | sourceTree = ""; 138 | }; 139 | /* End PBXGroup section */ 140 | 141 | /* Begin PBXHeadersBuildPhase section */ 142 | B9741FC62273A08300D69DF3 /* Headers */ = { 143 | isa = PBXHeadersBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | B9741FCF2273A08300D69DF3 /* FontFit.h in Headers */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXHeadersBuildPhase section */ 151 | 152 | /* Begin PBXNativeTarget section */ 153 | B9741FB022739FF200D69DF3 /* Example */ = { 154 | isa = PBXNativeTarget; 155 | buildConfigurationList = B9741FC322739FF300D69DF3 /* Build configuration list for PBXNativeTarget "Example" */; 156 | buildPhases = ( 157 | B9741FAD22739FF200D69DF3 /* Sources */, 158 | B9741FAE22739FF200D69DF3 /* Frameworks */, 159 | B9741FAF22739FF200D69DF3 /* Resources */, 160 | B9741FE22273A31C00D69DF3 /* Embed Frameworks */, 161 | ); 162 | buildRules = ( 163 | ); 164 | dependencies = ( 165 | B9741FDD2273A1C100D69DF3 /* PBXTargetDependency */, 166 | ); 167 | name = Example; 168 | productName = FontFit; 169 | productReference = B9741FB122739FF200D69DF3 /* Example.app */; 170 | productType = "com.apple.product-type.application"; 171 | }; 172 | B9741FCA2273A08300D69DF3 /* FontFit */ = { 173 | isa = PBXNativeTarget; 174 | buildConfigurationList = B9741FD02273A08300D69DF3 /* Build configuration list for PBXNativeTarget "FontFit" */; 175 | buildPhases = ( 176 | B9741FC62273A08300D69DF3 /* Headers */, 177 | B9741FC72273A08300D69DF3 /* Sources */, 178 | B9741FC82273A08300D69DF3 /* Frameworks */, 179 | B9741FC92273A08300D69DF3 /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | ); 185 | name = FontFit; 186 | productName = FontFit; 187 | productReference = B9741FCB2273A08300D69DF3 /* FontFit.framework */; 188 | productType = "com.apple.product-type.framework"; 189 | }; 190 | /* End PBXNativeTarget section */ 191 | 192 | /* Begin PBXProject section */ 193 | B9741FA922739FF200D69DF3 /* Project object */ = { 194 | isa = PBXProject; 195 | attributes = { 196 | LastSwiftUpdateCheck = 1010; 197 | LastUpgradeCheck = 1100; 198 | ORGANIZATIONNAME = "Jonathan Cardasis (C)"; 199 | TargetAttributes = { 200 | B9741FB022739FF200D69DF3 = { 201 | CreatedOnToolsVersion = 10.1; 202 | LastSwiftMigration = 1100; 203 | }; 204 | B9741FCA2273A08300D69DF3 = { 205 | CreatedOnToolsVersion = 10.1; 206 | LastSwiftMigration = 1100; 207 | }; 208 | }; 209 | }; 210 | buildConfigurationList = B9741FAC22739FF200D69DF3 /* Build configuration list for PBXProject "FontFit" */; 211 | compatibilityVersion = "Xcode 9.3"; 212 | developmentRegion = en; 213 | hasScannedForEncodings = 0; 214 | knownRegions = ( 215 | en, 216 | Base, 217 | ); 218 | mainGroup = B9741FA822739FF200D69DF3; 219 | productRefGroup = B9741FB222739FF200D69DF3 /* Products */; 220 | projectDirPath = ""; 221 | projectRoot = ""; 222 | targets = ( 223 | B9741FB022739FF200D69DF3 /* Example */, 224 | B9741FCA2273A08300D69DF3 /* FontFit */, 225 | ); 226 | }; 227 | /* End PBXProject section */ 228 | 229 | /* Begin PBXResourcesBuildPhase section */ 230 | B9741FAF22739FF200D69DF3 /* Resources */ = { 231 | isa = PBXResourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | B9741FBF22739FF300D69DF3 /* LaunchScreen.storyboard in Resources */, 235 | B9741FBC22739FF300D69DF3 /* Assets.xcassets in Resources */, 236 | B9741FBA22739FF200D69DF3 /* Main.storyboard in Resources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | B9741FC92273A08300D69DF3 /* Resources */ = { 241 | isa = PBXResourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | /* End PBXResourcesBuildPhase section */ 248 | 249 | /* Begin PBXSourcesBuildPhase section */ 250 | B9741FAD22739FF200D69DF3 /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | B9741FB722739FF200D69DF3 /* ViewController.swift in Sources */, 255 | B9741FDB2273A17200D69DF3 /* AutoFitLabel.swift in Sources */, 256 | B9741FB522739FF200D69DF3 /* AppDelegate.swift in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | B9741FC72273A08300D69DF3 /* Sources */ = { 261 | isa = PBXSourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | B9741FD42273A0A100D69DF3 /* TextSizingOption.swift in Sources */, 265 | B9741FD62273A0C300D69DF3 /* UIFont+FontFit.swift in Sources */, 266 | B9398C73227A29D900654C58 /* UITextView+FontFit.swift in Sources */, 267 | B9741FD92273A0F800D69DF3 /* UILabel+FontFit.swift in Sources */, 268 | ); 269 | runOnlyForDeploymentPostprocessing = 0; 270 | }; 271 | /* End PBXSourcesBuildPhase section */ 272 | 273 | /* Begin PBXTargetDependency section */ 274 | B9741FDD2273A1C100D69DF3 /* PBXTargetDependency */ = { 275 | isa = PBXTargetDependency; 276 | target = B9741FCA2273A08300D69DF3 /* FontFit */; 277 | targetProxy = B9741FDC2273A1C100D69DF3 /* PBXContainerItemProxy */; 278 | }; 279 | /* End PBXTargetDependency section */ 280 | 281 | /* Begin PBXVariantGroup section */ 282 | B9741FB822739FF200D69DF3 /* Main.storyboard */ = { 283 | isa = PBXVariantGroup; 284 | children = ( 285 | B9741FB922739FF200D69DF3 /* Base */, 286 | ); 287 | name = Main.storyboard; 288 | sourceTree = ""; 289 | }; 290 | B9741FBD22739FF300D69DF3 /* LaunchScreen.storyboard */ = { 291 | isa = PBXVariantGroup; 292 | children = ( 293 | B9741FBE22739FF300D69DF3 /* Base */, 294 | ); 295 | name = LaunchScreen.storyboard; 296 | sourceTree = ""; 297 | }; 298 | /* End PBXVariantGroup section */ 299 | 300 | /* Begin XCBuildConfiguration section */ 301 | B9741FC122739FF300D69DF3 /* Debug */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ALWAYS_SEARCH_USER_PATHS = NO; 305 | CLANG_ANALYZER_NONNULL = YES; 306 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 308 | CLANG_CXX_LIBRARY = "libc++"; 309 | CLANG_ENABLE_MODULES = YES; 310 | CLANG_ENABLE_OBJC_ARC = YES; 311 | CLANG_ENABLE_OBJC_WEAK = YES; 312 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_COMMA = YES; 315 | CLANG_WARN_CONSTANT_CONVERSION = YES; 316 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 317 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 318 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 319 | CLANG_WARN_EMPTY_BODY = YES; 320 | CLANG_WARN_ENUM_CONVERSION = YES; 321 | CLANG_WARN_INFINITE_RECURSION = YES; 322 | CLANG_WARN_INT_CONVERSION = YES; 323 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 324 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 325 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 328 | CLANG_WARN_STRICT_PROTOTYPES = YES; 329 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 330 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 331 | CLANG_WARN_UNREACHABLE_CODE = YES; 332 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 333 | CODE_SIGN_IDENTITY = "iPhone Developer"; 334 | COPY_PHASE_STRIP = NO; 335 | DEBUG_INFORMATION_FORMAT = dwarf; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | ENABLE_TESTABILITY = YES; 338 | GCC_C_LANGUAGE_STANDARD = gnu11; 339 | GCC_DYNAMIC_NO_PIC = NO; 340 | GCC_NO_COMMON_BLOCKS = YES; 341 | GCC_OPTIMIZATION_LEVEL = 0; 342 | GCC_PREPROCESSOR_DEFINITIONS = ( 343 | "DEBUG=1", 344 | "$(inherited)", 345 | ); 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 353 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 354 | MTL_FAST_MATH = YES; 355 | ONLY_ACTIVE_ARCH = YES; 356 | SDKROOT = iphoneos; 357 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 358 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 359 | }; 360 | name = Debug; 361 | }; 362 | B9741FC222739FF300D69DF3 /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_ANALYZER_NONNULL = YES; 367 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 368 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 369 | CLANG_CXX_LIBRARY = "libc++"; 370 | CLANG_ENABLE_MODULES = YES; 371 | CLANG_ENABLE_OBJC_ARC = YES; 372 | CLANG_ENABLE_OBJC_WEAK = YES; 373 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 374 | CLANG_WARN_BOOL_CONVERSION = YES; 375 | CLANG_WARN_COMMA = YES; 376 | CLANG_WARN_CONSTANT_CONVERSION = YES; 377 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 378 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 379 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 380 | CLANG_WARN_EMPTY_BODY = YES; 381 | CLANG_WARN_ENUM_CONVERSION = YES; 382 | CLANG_WARN_INFINITE_RECURSION = YES; 383 | CLANG_WARN_INT_CONVERSION = YES; 384 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 385 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 386 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 389 | CLANG_WARN_STRICT_PROTOTYPES = YES; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 392 | CLANG_WARN_UNREACHABLE_CODE = YES; 393 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 394 | CODE_SIGN_IDENTITY = "iPhone Developer"; 395 | COPY_PHASE_STRIP = NO; 396 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 397 | ENABLE_NS_ASSERTIONS = NO; 398 | ENABLE_STRICT_OBJC_MSGSEND = YES; 399 | GCC_C_LANGUAGE_STANDARD = gnu11; 400 | GCC_NO_COMMON_BLOCKS = YES; 401 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 402 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 403 | GCC_WARN_UNDECLARED_SELECTOR = YES; 404 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 405 | GCC_WARN_UNUSED_FUNCTION = YES; 406 | GCC_WARN_UNUSED_VARIABLE = YES; 407 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 408 | MTL_ENABLE_DEBUG_INFO = NO; 409 | MTL_FAST_MATH = YES; 410 | SDKROOT = iphoneos; 411 | SWIFT_COMPILATION_MODE = wholemodule; 412 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 413 | VALIDATE_PRODUCT = YES; 414 | }; 415 | name = Release; 416 | }; 417 | B9741FC422739FF300D69DF3 /* Debug */ = { 418 | isa = XCBuildConfiguration; 419 | buildSettings = { 420 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 421 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 422 | CODE_SIGN_STYLE = Automatic; 423 | INFOPLIST_FILE = Example/Info.plist; 424 | LD_RUNPATH_SEARCH_PATHS = ( 425 | "$(inherited)", 426 | "@executable_path/Frameworks", 427 | ); 428 | PRODUCT_BUNDLE_IDENTIFIER = com.jonathancardasis.FontFitExample; 429 | PRODUCT_NAME = "$(TARGET_NAME)"; 430 | SWIFT_VERSION = 5.0; 431 | TARGETED_DEVICE_FAMILY = "1,2"; 432 | }; 433 | name = Debug; 434 | }; 435 | B9741FC522739FF300D69DF3 /* Release */ = { 436 | isa = XCBuildConfiguration; 437 | buildSettings = { 438 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 439 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 440 | CODE_SIGN_STYLE = Automatic; 441 | INFOPLIST_FILE = Example/Info.plist; 442 | LD_RUNPATH_SEARCH_PATHS = ( 443 | "$(inherited)", 444 | "@executable_path/Frameworks", 445 | ); 446 | PRODUCT_BUNDLE_IDENTIFIER = com.jonathancardasis.FontFitExample; 447 | PRODUCT_NAME = "$(TARGET_NAME)"; 448 | SWIFT_VERSION = 5.0; 449 | TARGETED_DEVICE_FAMILY = "1,2"; 450 | }; 451 | name = Release; 452 | }; 453 | B9741FD12273A08300D69DF3 /* Debug */ = { 454 | isa = XCBuildConfiguration; 455 | buildSettings = { 456 | CLANG_ENABLE_MODULES = YES; 457 | CODE_SIGN_IDENTITY = ""; 458 | CODE_SIGN_STYLE = Automatic; 459 | CURRENT_PROJECT_VERSION = 1; 460 | DEFINES_MODULE = YES; 461 | DYLIB_COMPATIBILITY_VERSION = 1; 462 | DYLIB_CURRENT_VERSION = 1; 463 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 464 | INFOPLIST_FILE = FontFit/Info.plist; 465 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 466 | LD_RUNPATH_SEARCH_PATHS = ( 467 | "$(inherited)", 468 | "@executable_path/Frameworks", 469 | "@loader_path/Frameworks", 470 | ); 471 | PRODUCT_BUNDLE_IDENTIFIER = com.jonathancardasis.FontFit; 472 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 473 | SKIP_INSTALL = YES; 474 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 475 | SWIFT_VERSION = 5.0; 476 | TARGETED_DEVICE_FAMILY = "1,2"; 477 | VERSIONING_SYSTEM = "apple-generic"; 478 | VERSION_INFO_PREFIX = ""; 479 | }; 480 | name = Debug; 481 | }; 482 | B9741FD22273A08300D69DF3 /* Release */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | CLANG_ENABLE_MODULES = YES; 486 | CODE_SIGN_IDENTITY = ""; 487 | CODE_SIGN_STYLE = Automatic; 488 | CURRENT_PROJECT_VERSION = 1; 489 | DEFINES_MODULE = YES; 490 | DYLIB_COMPATIBILITY_VERSION = 1; 491 | DYLIB_CURRENT_VERSION = 1; 492 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 493 | INFOPLIST_FILE = FontFit/Info.plist; 494 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 495 | LD_RUNPATH_SEARCH_PATHS = ( 496 | "$(inherited)", 497 | "@executable_path/Frameworks", 498 | "@loader_path/Frameworks", 499 | ); 500 | PRODUCT_BUNDLE_IDENTIFIER = com.jonathancardasis.FontFit; 501 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 502 | SKIP_INSTALL = YES; 503 | SWIFT_VERSION = 5.0; 504 | TARGETED_DEVICE_FAMILY = "1,2"; 505 | VERSIONING_SYSTEM = "apple-generic"; 506 | VERSION_INFO_PREFIX = ""; 507 | }; 508 | name = Release; 509 | }; 510 | /* End XCBuildConfiguration section */ 511 | 512 | /* Begin XCConfigurationList section */ 513 | B9741FAC22739FF200D69DF3 /* Build configuration list for PBXProject "FontFit" */ = { 514 | isa = XCConfigurationList; 515 | buildConfigurations = ( 516 | B9741FC122739FF300D69DF3 /* Debug */, 517 | B9741FC222739FF300D69DF3 /* Release */, 518 | ); 519 | defaultConfigurationIsVisible = 0; 520 | defaultConfigurationName = Release; 521 | }; 522 | B9741FC322739FF300D69DF3 /* Build configuration list for PBXNativeTarget "Example" */ = { 523 | isa = XCConfigurationList; 524 | buildConfigurations = ( 525 | B9741FC422739FF300D69DF3 /* Debug */, 526 | B9741FC522739FF300D69DF3 /* Release */, 527 | ); 528 | defaultConfigurationIsVisible = 0; 529 | defaultConfigurationName = Release; 530 | }; 531 | B9741FD02273A08300D69DF3 /* Build configuration list for PBXNativeTarget "FontFit" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | B9741FD12273A08300D69DF3 /* Debug */, 535 | B9741FD22273A08300D69DF3 /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | defaultConfigurationName = Release; 539 | }; 540 | /* End XCConfigurationList section */ 541 | }; 542 | rootObject = B9741FA922739FF200D69DF3 /* Project object */; 543 | } 544 | -------------------------------------------------------------------------------- /FontFit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FontFit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FontFit.xcodeproj/project.xcworkspace/xcuserdata/hz6y8w.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joncardasis/FontFit/2ab7230881b40b7e2728c566fbce098865fa5972/FontFit.xcodeproj/project.xcworkspace/xcuserdata/hz6y8w.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /FontFit.xcodeproj/xcuserdata/hz6y8w.xcuserdatad/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /FontFit.xcodeproj/xcuserdata/hz6y8w.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Example.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | FontFit.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /FontFit/FontFit.h: -------------------------------------------------------------------------------- 1 | // 2 | // FontFit.h 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for FontFit. 12 | FOUNDATION_EXPORT double FontFitVersionNumber; 13 | 14 | //! Project version string for FontFit. 15 | FOUNDATION_EXPORT const unsigned char FontFitVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /FontFit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /FontFit/TextSizingOption.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextSizingOption.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum TextSizingOption: Equatable { 12 | case preferredLineCount(UInt) 13 | case fillContainer 14 | 15 | public static func == (lhs: TextSizingOption, rhs: TextSizingOption) -> Bool { 16 | switch (lhs, rhs) { 17 | case (let .preferredLineCount(lines1), let .preferredLineCount(lines2)): 18 | return lines1 == lines2 19 | case (.fillContainer,.fillContainer): 20 | return true 21 | default: 22 | return false 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /FontFit/UIFont+FontFit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIFont+FontFit.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public extension UIFont { 12 | 13 | /** 14 | Provides the largest font which fits the text in the given bounds. 15 | */ 16 | static func fontFittingText(_ text: String, in bounds: CGSize, fontDescriptor: UIFontDescriptor, option: TextSizingOption) -> UIFont? { 17 | let properBounds = CGRect(origin: .zero, size: bounds) 18 | let largestFontSize = Int(bounds.height) 19 | let constrainingBounds = CGSize(width: properBounds.width, height: CGFloat.infinity) 20 | 21 | let bestFittingFontSize: Int? = (1...largestFontSize).reversed().first(where: { fontSize in 22 | let font = UIFont(descriptor: fontDescriptor, size: CGFloat(fontSize)) 23 | let currentFrame = text.boundingRect(with: constrainingBounds, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font], context: nil) 24 | 25 | if properBounds.contains(currentFrame) { 26 | let currentFrameLineCount = Int(ceil(currentFrame.height / font.lineHeight)) 27 | if case .preferredLineCount(let lineCount) = option, currentFrameLineCount > max(lineCount, 1) { 28 | return false 29 | } 30 | return true 31 | } 32 | 33 | return false 34 | }) 35 | 36 | guard let fontSize = bestFittingFontSize else { return nil } 37 | return UIFont(descriptor: fontDescriptor, size: CGFloat(fontSize)) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /FontFit/UILabel+FontFit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+FontFit.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 4/26/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public extension UILabel { 12 | 13 | /** 14 | Autosizes `font` to the largest value where the text fills the `maxLines` provided. 15 | 16 | Depending on the bounds of the view, the actual number of lines occupied by the text may 17 | be less than the preferred amount provided. 18 | */ 19 | func fitText(maxLines: UInt) { 20 | guard let text = text else { return } 21 | numberOfLines = 0 22 | self.font = UIFont.fontFittingText(text, in: bounds.size, fontDescriptor: font.fontDescriptor, option: .preferredLineCount(maxLines)) 23 | } 24 | 25 | /** 26 | Autosizes `font` to the largest value where the text can still be contained in the view's bounds. 27 | */ 28 | func fitTextToBounds() { 29 | guard let text = text else { return } 30 | numberOfLines = 0 31 | self.font = UIFont.fontFittingText(text, in: bounds.size, fontDescriptor: font.fontDescriptor, option: .fillContainer) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /FontFit/UITextView+FontFit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+FontFit.swift 3 | // FontFit 4 | // 5 | // Created by Jonathan Cardasis (C) on 5/1/19. 6 | // Copyright © 2019 Jonathan Cardasis (C). All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | public extension UITextView { 13 | 14 | /** 15 | Autosizes `font` to the largest value where the text fills the `maxLines` provided. 16 | 17 | Depending on the bounds of the view, the actual number of lines occupied by the text may 18 | be less than the preferred amount provided. 19 | */ 20 | func fitText(maxLines: UInt) { 21 | guard let text = text else { return } 22 | let font = self.font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize) 23 | self.font = UIFont.fontFittingText(text, in: textBoundingBox.size, fontDescriptor: font.fontDescriptor, option: .preferredLineCount(maxLines)) 24 | } 25 | 26 | /** 27 | Autosizes `font` to the largest value where the text can still be contained in the view's bounds. 28 | */ 29 | func fitTextToBounds() { 30 | guard let text = text else { return } 31 | let font = self.font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize) 32 | self.font = UIFont.fontFittingText(text, in: textBoundingBox.size, fontDescriptor: font.fontDescriptor, option: .fillContainer) 33 | } 34 | 35 | private var textBoundingBox: CGRect { 36 | var textInsets: UIEdgeInsets = textContainerInset 37 | textInsets.left += textContainer.lineFragmentPadding 38 | textInsets.right += textContainer.lineFragmentPadding 39 | return bounds.inset(by: textInsets) 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jonathan Cardasis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | ChromaColorPicker 2.0 3 |

4 | 5 |

6 | 7 | 8 | 9 | 10 |

11 | 12 |

13 | 14 | 15 |

16 | 17 | ## Abstract 18 | FontFit scales the `font` size of a text element (i.e. `UILabel` or `UITextView`) to fill it's container. 19 | 20 | FontFit is the missing inverse of `sizeToFit()`. The `FontFit` extensions are a more detailed implementation of UILabel's [adjustsFontSizeToFitWidth](https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth) which only _reduces_ font size. 21 | 22 | ## Examples 23 | **Note**: A full example use case can be found in the _Example_ project. 24 | 25 | ```Swift 26 | let label = UILabel(frame: ...) 27 | 28 | // Increase font to fill the label's frame. 29 | label.fitTextToBounds() 30 | ``` 31 | 32 | ```Swift 33 | let label = UILabel(frame: ...) 34 | 35 | // Increase font to fill the label's frame, attempting to distribute onto, at most, 2 lines. 36 | label.fitText(maxLines: 2) 37 | ``` 38 | ## License 39 | FontFit is available under the MIT license. See the LICENSE file for more info. 40 | --------------------------------------------------------------------------------