├── README.md ├── ZLIconLabel.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── apple.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── apple.xcuserdatad │ └── xcschemes │ ├── ZLIconLabel.xcscheme │ └── xcschememanagement.plist └── ZLIconLabel ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Bell.imageset │ ├── Contents.json │ ├── image.png │ ├── image@2x.png │ └── image@3x.png └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── Screen Shot.png ├── UIView+Extension.h ├── UIView+Extension.m ├── ViewController.h ├── ViewController.m ├── ZLIconLabel.h ├── ZLIconLabel.m └── main.m /README.md: -------------------------------------------------------------------------------- 1 | # ZLIconLabel 2 | 3 | The Objective-C version of [SMIconLabel](https://github.com/anatoliyv/SMIconLabel). 4 | 5 | UILabel with possibility to place small icon on the left or on the right side. Take a look at preview image or build smaple app to see how it works. 6 | 7 | ![Screen Shot](https://github.com/angelen10/ZLIconLabel/blob/master/ZLIconLabel/Screen%20Shot.png) 8 | 9 | **Note:** To make icon works as expected you should set `numberOfLines = 1` for ZLIconLabel 10 | 11 | ### Installation 12 | 13 | This repo has an example project, but if you want to include SMIconLabel you need these files: `UIView+Extension.h`, `UIView+Extension.m`, `ZLIconLabel.h`, `ZLIconLabel.m`. 14 | 15 | ### Usage 16 | 17 | Usage is as simple as possible. Here is an example: 18 | 19 | ``` 20 | UIImage *image = [UIImage imageNamed:@"Bell"]; 21 | ZLIconLabel *labelLeft = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50, self.view.width - 20 * 2, 30)]; 22 | labelLeft.text = @"Icon on the left, text on the left"; 23 | labelLeft.textColor = [UIColor orangeColor]; 24 | labelLeft.icon = image; 25 | labelLeft.iconPosition = ZLIconLabelPositionLeft; 26 | labelLeft.textAlignment = NSTextAlignmentLeft; 27 | [self.view addSubview:labelLeft]; 28 | ``` 29 | Enjoy! 30 | -------------------------------------------------------------------------------- /ZLIconLabel.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1863B1281CBBAE1D004D5114 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1863B1271CBBAE1D004D5114 /* main.m */; }; 11 | 1863B12B1CBBAE1D004D5114 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1863B12A1CBBAE1D004D5114 /* AppDelegate.m */; }; 12 | 1863B12E1CBBAE1D004D5114 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1863B12D1CBBAE1D004D5114 /* ViewController.m */; }; 13 | 1863B1311CBBAE1D004D5114 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1863B12F1CBBAE1D004D5114 /* Main.storyboard */; }; 14 | 1863B1331CBBAE1D004D5114 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1863B1321CBBAE1D004D5114 /* Assets.xcassets */; }; 15 | 1863B1361CBBAE1D004D5114 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1863B1341CBBAE1D004D5114 /* LaunchScreen.storyboard */; }; 16 | 1863B13F1CBBAE56004D5114 /* ZLIconLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 1863B13E1CBBAE56004D5114 /* ZLIconLabel.m */; }; 17 | 1863B1431CBBB81F004D5114 /* UIView+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 1863B1421CBBB81F004D5114 /* UIView+Extension.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 1863B1231CBBAE1D004D5114 /* ZLIconLabel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZLIconLabel.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 1863B1271CBBAE1D004D5114 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 23 | 1863B1291CBBAE1D004D5114 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 24 | 1863B12A1CBBAE1D004D5114 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 25 | 1863B12C1CBBAE1D004D5114 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 26 | 1863B12D1CBBAE1D004D5114 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 27 | 1863B1301CBBAE1D004D5114 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28 | 1863B1321CBBAE1D004D5114 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 1863B1351CBBAE1D004D5114 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 30 | 1863B1371CBBAE1D004D5114 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 1863B13D1CBBAE56004D5114 /* ZLIconLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZLIconLabel.h; sourceTree = ""; }; 32 | 1863B13E1CBBAE56004D5114 /* ZLIconLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZLIconLabel.m; sourceTree = ""; }; 33 | 1863B1411CBBB81F004D5114 /* UIView+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Extension.h"; sourceTree = ""; }; 34 | 1863B1421CBBB81F004D5114 /* UIView+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Extension.m"; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 1863B1201CBBAE1D004D5114 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 1863B11A1CBBAE1D004D5114 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 1863B1251CBBAE1D004D5114 /* ZLIconLabel */, 52 | 1863B1241CBBAE1D004D5114 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 1863B1241CBBAE1D004D5114 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 1863B1231CBBAE1D004D5114 /* ZLIconLabel.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 1863B1251CBBAE1D004D5114 /* ZLIconLabel */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 1863B1291CBBAE1D004D5114 /* AppDelegate.h */, 68 | 1863B12A1CBBAE1D004D5114 /* AppDelegate.m */, 69 | 1863B12C1CBBAE1D004D5114 /* ViewController.h */, 70 | 1863B12D1CBBAE1D004D5114 /* ViewController.m */, 71 | 1863B12F1CBBAE1D004D5114 /* Main.storyboard */, 72 | 1863B1321CBBAE1D004D5114 /* Assets.xcassets */, 73 | 1863B1341CBBAE1D004D5114 /* LaunchScreen.storyboard */, 74 | 1863B1371CBBAE1D004D5114 /* Info.plist */, 75 | 1863B1261CBBAE1D004D5114 /* Supporting Files */, 76 | 1863B13D1CBBAE56004D5114 /* ZLIconLabel.h */, 77 | 1863B13E1CBBAE56004D5114 /* ZLIconLabel.m */, 78 | 1863B1411CBBB81F004D5114 /* UIView+Extension.h */, 79 | 1863B1421CBBB81F004D5114 /* UIView+Extension.m */, 80 | ); 81 | path = ZLIconLabel; 82 | sourceTree = ""; 83 | }; 84 | 1863B1261CBBAE1D004D5114 /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 1863B1271CBBAE1D004D5114 /* main.m */, 88 | ); 89 | name = "Supporting Files"; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXNativeTarget section */ 95 | 1863B1221CBBAE1D004D5114 /* ZLIconLabel */ = { 96 | isa = PBXNativeTarget; 97 | buildConfigurationList = 1863B13A1CBBAE1D004D5114 /* Build configuration list for PBXNativeTarget "ZLIconLabel" */; 98 | buildPhases = ( 99 | 1863B11F1CBBAE1D004D5114 /* Sources */, 100 | 1863B1201CBBAE1D004D5114 /* Frameworks */, 101 | 1863B1211CBBAE1D004D5114 /* Resources */, 102 | ); 103 | buildRules = ( 104 | ); 105 | dependencies = ( 106 | ); 107 | name = ZLIconLabel; 108 | productName = ZLIconLabel; 109 | productReference = 1863B1231CBBAE1D004D5114 /* ZLIconLabel.app */; 110 | productType = "com.apple.product-type.application"; 111 | }; 112 | /* End PBXNativeTarget section */ 113 | 114 | /* Begin PBXProject section */ 115 | 1863B11B1CBBAE1D004D5114 /* Project object */ = { 116 | isa = PBXProject; 117 | attributes = { 118 | LastUpgradeCheck = 0730; 119 | ORGANIZATIONNAME = ANGELEN; 120 | TargetAttributes = { 121 | 1863B1221CBBAE1D004D5114 = { 122 | CreatedOnToolsVersion = 7.3; 123 | }; 124 | }; 125 | }; 126 | buildConfigurationList = 1863B11E1CBBAE1D004D5114 /* Build configuration list for PBXProject "ZLIconLabel" */; 127 | compatibilityVersion = "Xcode 3.2"; 128 | developmentRegion = English; 129 | hasScannedForEncodings = 0; 130 | knownRegions = ( 131 | en, 132 | Base, 133 | ); 134 | mainGroup = 1863B11A1CBBAE1D004D5114; 135 | productRefGroup = 1863B1241CBBAE1D004D5114 /* Products */; 136 | projectDirPath = ""; 137 | projectRoot = ""; 138 | targets = ( 139 | 1863B1221CBBAE1D004D5114 /* ZLIconLabel */, 140 | ); 141 | }; 142 | /* End PBXProject section */ 143 | 144 | /* Begin PBXResourcesBuildPhase section */ 145 | 1863B1211CBBAE1D004D5114 /* Resources */ = { 146 | isa = PBXResourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | 1863B1361CBBAE1D004D5114 /* LaunchScreen.storyboard in Resources */, 150 | 1863B1331CBBAE1D004D5114 /* Assets.xcassets in Resources */, 151 | 1863B1311CBBAE1D004D5114 /* Main.storyboard in Resources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXResourcesBuildPhase section */ 156 | 157 | /* Begin PBXSourcesBuildPhase section */ 158 | 1863B11F1CBBAE1D004D5114 /* Sources */ = { 159 | isa = PBXSourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 1863B1431CBBB81F004D5114 /* UIView+Extension.m in Sources */, 163 | 1863B12E1CBBAE1D004D5114 /* ViewController.m in Sources */, 164 | 1863B12B1CBBAE1D004D5114 /* AppDelegate.m in Sources */, 165 | 1863B1281CBBAE1D004D5114 /* main.m in Sources */, 166 | 1863B13F1CBBAE56004D5114 /* ZLIconLabel.m in Sources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXSourcesBuildPhase section */ 171 | 172 | /* Begin PBXVariantGroup section */ 173 | 1863B12F1CBBAE1D004D5114 /* Main.storyboard */ = { 174 | isa = PBXVariantGroup; 175 | children = ( 176 | 1863B1301CBBAE1D004D5114 /* Base */, 177 | ); 178 | name = Main.storyboard; 179 | sourceTree = ""; 180 | }; 181 | 1863B1341CBBAE1D004D5114 /* LaunchScreen.storyboard */ = { 182 | isa = PBXVariantGroup; 183 | children = ( 184 | 1863B1351CBBAE1D004D5114 /* Base */, 185 | ); 186 | name = LaunchScreen.storyboard; 187 | sourceTree = ""; 188 | }; 189 | /* End PBXVariantGroup section */ 190 | 191 | /* Begin XCBuildConfiguration section */ 192 | 1863B1381CBBAE1D004D5114 /* Debug */ = { 193 | isa = XCBuildConfiguration; 194 | buildSettings = { 195 | ALWAYS_SEARCH_USER_PATHS = NO; 196 | CLANG_ANALYZER_NONNULL = YES; 197 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 198 | CLANG_CXX_LIBRARY = "libc++"; 199 | CLANG_ENABLE_MODULES = YES; 200 | CLANG_ENABLE_OBJC_ARC = YES; 201 | CLANG_WARN_BOOL_CONVERSION = YES; 202 | CLANG_WARN_CONSTANT_CONVERSION = YES; 203 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 204 | CLANG_WARN_EMPTY_BODY = YES; 205 | CLANG_WARN_ENUM_CONVERSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 208 | CLANG_WARN_UNREACHABLE_CODE = YES; 209 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 210 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 211 | COPY_PHASE_STRIP = NO; 212 | DEBUG_INFORMATION_FORMAT = dwarf; 213 | ENABLE_STRICT_OBJC_MSGSEND = YES; 214 | ENABLE_TESTABILITY = YES; 215 | GCC_C_LANGUAGE_STANDARD = gnu99; 216 | GCC_DYNAMIC_NO_PIC = NO; 217 | GCC_NO_COMMON_BLOCKS = YES; 218 | GCC_OPTIMIZATION_LEVEL = 0; 219 | GCC_PREPROCESSOR_DEFINITIONS = ( 220 | "DEBUG=1", 221 | "$(inherited)", 222 | ); 223 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 224 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 225 | GCC_WARN_UNDECLARED_SELECTOR = YES; 226 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 227 | GCC_WARN_UNUSED_FUNCTION = YES; 228 | GCC_WARN_UNUSED_VARIABLE = YES; 229 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 230 | MTL_ENABLE_DEBUG_INFO = YES; 231 | ONLY_ACTIVE_ARCH = YES; 232 | SDKROOT = iphoneos; 233 | TARGETED_DEVICE_FAMILY = "1,2"; 234 | }; 235 | name = Debug; 236 | }; 237 | 1863B1391CBBAE1D004D5114 /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 243 | CLANG_CXX_LIBRARY = "libc++"; 244 | CLANG_ENABLE_MODULES = YES; 245 | CLANG_ENABLE_OBJC_ARC = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INT_CONVERSION = YES; 252 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | TARGETED_DEVICE_FAMILY = "1,2"; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | 1863B13B1CBBAE1D004D5114 /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | INFOPLIST_FILE = ZLIconLabel/Info.plist; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = me.angelen.ZLIconLabel; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | }; 285 | name = Debug; 286 | }; 287 | 1863B13C1CBBAE1D004D5114 /* Release */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | INFOPLIST_FILE = ZLIconLabel/Info.plist; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = me.angelen.ZLIconLabel; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | }; 296 | name = Release; 297 | }; 298 | /* End XCBuildConfiguration section */ 299 | 300 | /* Begin XCConfigurationList section */ 301 | 1863B11E1CBBAE1D004D5114 /* Build configuration list for PBXProject "ZLIconLabel" */ = { 302 | isa = XCConfigurationList; 303 | buildConfigurations = ( 304 | 1863B1381CBBAE1D004D5114 /* Debug */, 305 | 1863B1391CBBAE1D004D5114 /* Release */, 306 | ); 307 | defaultConfigurationIsVisible = 0; 308 | defaultConfigurationName = Release; 309 | }; 310 | 1863B13A1CBBAE1D004D5114 /* Build configuration list for PBXNativeTarget "ZLIconLabel" */ = { 311 | isa = XCConfigurationList; 312 | buildConfigurations = ( 313 | 1863B13B1CBBAE1D004D5114 /* Debug */, 314 | 1863B13C1CBBAE1D004D5114 /* Release */, 315 | ); 316 | defaultConfigurationIsVisible = 0; 317 | }; 318 | /* End XCConfigurationList section */ 319 | }; 320 | rootObject = 1863B11B1CBBAE1D004D5114 /* Project object */; 321 | } 322 | -------------------------------------------------------------------------------- /ZLIconLabel.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZLIconLabel.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angelen10/ZLIconLabel/bd582af58d2fdcf1ae2a3231c5fa0ba178066200/ZLIconLabel.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ZLIconLabel.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/ZLIconLabel.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ZLIconLabel.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZLIconLabel.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1863B1221CBBAE1D004D5114 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ZLIconLabel/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /ZLIconLabel/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/Bell.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "image.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "image@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "image@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/Bell.imageset/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angelen10/ZLIconLabel/bd582af58d2fdcf1ae2a3231c5fa0ba178066200/ZLIconLabel/Assets.xcassets/Bell.imageset/image.png -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/Bell.imageset/image@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angelen10/ZLIconLabel/bd582af58d2fdcf1ae2a3231c5fa0ba178066200/ZLIconLabel/Assets.xcassets/Bell.imageset/image@2x.png -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/Bell.imageset/image@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angelen10/ZLIconLabel/bd582af58d2fdcf1ae2a3231c5fa0ba178066200/ZLIconLabel/Assets.xcassets/Bell.imageset/image@3x.png -------------------------------------------------------------------------------- /ZLIconLabel/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ZLIconLabel/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 | 27 | 28 | -------------------------------------------------------------------------------- /ZLIconLabel/Base.lproj/Main.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 | -------------------------------------------------------------------------------- /ZLIconLabel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ZLIconLabel/Screen Shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/angelen10/ZLIconLabel/bd582af58d2fdcf1ae2a3231c5fa0ba178066200/ZLIconLabel/Screen Shot.png -------------------------------------------------------------------------------- /ZLIconLabel/UIView+Extension.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface UIView (Extension) 4 | 5 | @property (nonatomic, assign) CGFloat x; 6 | @property (nonatomic, assign) CGFloat y; 7 | @property (nonatomic, assign) CGFloat width; 8 | @property (nonatomic, assign) CGFloat height; 9 | @property (nonatomic, assign) CGSize size; 10 | @property (nonatomic, assign) CGPoint origin; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /ZLIconLabel/UIView+Extension.m: -------------------------------------------------------------------------------- 1 | #import "UIView+Extension.h" 2 | 3 | @implementation UIView (Extension) 4 | 5 | - (void)setX:(CGFloat)x { 6 | CGRect frame = self.frame; 7 | frame.origin.x = x; 8 | self.frame = frame; 9 | } 10 | 11 | - (void)setY:(CGFloat)y { 12 | CGRect frame = self.frame; 13 | frame.origin.y = y; 14 | self.frame = frame; 15 | } 16 | 17 | - (CGFloat)x { 18 | return self.frame.origin.x; 19 | } 20 | 21 | - (CGFloat)y { 22 | return self.frame.origin.y; 23 | } 24 | 25 | - (void)setWidth:(CGFloat)width { 26 | CGRect frame = self.frame; 27 | frame.size.width = width; 28 | self.frame = frame; 29 | } 30 | 31 | - (void)setHeight:(CGFloat)height { 32 | CGRect frame = self.frame; 33 | frame.size.height = height; 34 | self.frame = frame; 35 | } 36 | 37 | - (CGFloat)height { 38 | return self.frame.size.height; 39 | } 40 | 41 | - (CGFloat)width { 42 | return self.frame.size.width; 43 | } 44 | 45 | - (void)setSize:(CGSize)size { 46 | CGRect frame = self.frame; 47 | frame.size = size; 48 | self.frame = frame; 49 | } 50 | 51 | - (CGSize)size { 52 | return self.frame.size; 53 | } 54 | 55 | - (void)setOrigin:(CGPoint)origin { 56 | CGRect frame = self.frame; 57 | frame.origin = origin; 58 | self.frame = frame; 59 | } 60 | 61 | - (CGPoint)origin { 62 | return self.frame.origin; 63 | } 64 | @end 65 | -------------------------------------------------------------------------------- /ZLIconLabel/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ZLIconLabel/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ZLIconLabel.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | self.view.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.9]; 22 | 23 | UIImage *image = [UIImage imageNamed:@"Bell"]; 24 | 25 | ZLIconLabel *labelLeft = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50, self.view.width - 20 * 2, 30)]; 26 | ZLIconLabel *labelLeft2 = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50 * 2, self.view.width - 20 * 2, 30)]; 27 | ZLIconLabel *labelRight = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50 * 3, self.view.width - 20 * 2, 30)]; 28 | ZLIconLabel *labelRight2 = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50 * 4, self.view.width - 20 * 2, 30)]; 29 | ZLIconLabel *labelCenter = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50 * 5, self.view.width - 20 * 2, 30)]; 30 | ZLIconLabel *labelCenter2 = [[ZLIconLabel alloc] initWithFrame:CGRectMake(20, 50 * 6, self.view.width - 20 * 2, 30)]; 31 | 32 | labelLeft.text = @"Icon on the left, text on the left"; 33 | labelLeft2.text = @"Icon on the right, text on the left"; 34 | labelRight.text = @"Icon on the left, text on the right"; 35 | labelRight2.text = @"Icon on the right, text on the right"; 36 | labelCenter.text = @"Icon on the left, text on the center"; 37 | labelCenter2.text = @"Icon on the right, text on the center"; 38 | 39 | labelLeft.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 40 | labelLeft2.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 41 | labelRight.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 42 | labelRight2.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 43 | labelCenter.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 44 | labelCenter2.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.2]; 45 | 46 | labelLeft.font = [UIFont systemFontOfSize:12]; 47 | labelLeft2.font = [UIFont systemFontOfSize:12]; 48 | labelRight.font = [UIFont systemFontOfSize:12]; 49 | labelRight2.font = [UIFont systemFontOfSize:12]; 50 | labelCenter.font = [UIFont systemFontOfSize:12]; 51 | labelCenter2.font = [UIFont systemFontOfSize:12]; 52 | 53 | labelLeft.textColor = [UIColor orangeColor]; 54 | labelLeft2.textColor = [UIColor orangeColor]; 55 | labelRight.textColor = [UIColor orangeColor]; 56 | labelRight2.textColor = [UIColor orangeColor]; 57 | labelCenter.textColor = [UIColor orangeColor]; 58 | labelCenter2.textColor = [UIColor orangeColor]; 59 | 60 | labelLeft.icon = image; 61 | labelLeft2.icon = image; 62 | labelRight.icon = image; 63 | labelRight2.icon = image; 64 | labelCenter.icon = image; 65 | labelCenter2.icon = image; 66 | 67 | labelLeft.clipsToBounds = true; 68 | labelLeft2.clipsToBounds = true; 69 | labelRight.clipsToBounds = true; 70 | labelRight2.clipsToBounds = true; 71 | labelCenter.clipsToBounds = true; 72 | labelCenter2.clipsToBounds = true; 73 | 74 | labelLeft.layer.cornerRadius = 4; 75 | labelLeft2.layer.cornerRadius = 4; 76 | labelRight.layer.cornerRadius = 4; 77 | labelRight2.layer.cornerRadius = 4; 78 | labelCenter.layer.cornerRadius = 4; 79 | labelCenter2.layer.cornerRadius = 4; 80 | 81 | labelLeft.iconPadding = 5; 82 | labelLeft2.iconPadding = 5; 83 | labelRight.iconPadding = 5; 84 | labelRight2.iconPadding = 5; 85 | labelCenter.iconPadding = 5; 86 | labelCenter2.iconPadding = 5; 87 | 88 | labelLeft.iconPosition = ZLIconLabelPositionLeft; 89 | labelLeft.textAlignment = NSTextAlignmentLeft; 90 | 91 | labelLeft2.iconPosition = ZLIconLabelPositionRight; 92 | labelLeft2.textAlignment = NSTextAlignmentLeft; 93 | 94 | labelRight.iconPosition = ZLIconLabelPositionLeft; 95 | labelRight.textAlignment = NSTextAlignmentRight; 96 | 97 | labelRight2.iconPosition = ZLIconLabelPositionRight; 98 | labelRight2.textAlignment = NSTextAlignmentRight; 99 | 100 | labelCenter.iconPosition = ZLIconLabelPositionLeft; 101 | labelCenter.textAlignment = NSTextAlignmentCenter; 102 | 103 | labelCenter2.iconPosition = ZLIconLabelPositionRight; 104 | labelCenter2.textAlignment = NSTextAlignmentCenter; 105 | 106 | [self.view addSubview:labelLeft]; 107 | [self.view addSubview:labelLeft2]; 108 | [self.view addSubview:labelRight]; 109 | [self.view addSubview:labelRight2]; 110 | [self.view addSubview:labelCenter]; 111 | [self.view addSubview:labelCenter2]; 112 | } 113 | 114 | - (void)didReceiveMemoryWarning { 115 | [super didReceiveMemoryWarning]; 116 | // Dispose of any resources that can be recreated. 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /ZLIconLabel/ZLIconLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZLIconLabel.h 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "UIView+Extension.h" 11 | 12 | typedef NS_ENUM(NSUInteger, ZLIconLabelPosition) { 13 | ZLIconLabelPositionLeft, // 文本左边 14 | ZLIconLabelPositionRight, // 文本右边 15 | }; 16 | 17 | @interface ZLIconLabel : UILabel 18 | 19 | /** Image that will be placed with a text*/ 20 | @property (nonatomic, strong) UIImage *icon; 21 | 22 | /** Position of an image */ 23 | @property (nonatomic, assign) ZLIconLabelPosition iconPosition; 24 | 25 | /** Additional spacing between text and image */ 26 | @property (nonatomic, assign) CGFloat iconPadding; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /ZLIconLabel/ZLIconLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZLIconLabel.m 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import "ZLIconLabel.h" 10 | 11 | @interface ZLIconLabel() { 12 | UIImageView *_iconView; 13 | } 14 | 15 | @end 16 | 17 | @implementation ZLIconLabel 18 | 19 | - (void)viewDidLoad { 20 | NSLog(@"viewDidLoad.."); 21 | } 22 | 23 | // Only override drawRect: if you perform custom drawing. 24 | // An empty implementation adversely affects performance during animation. 25 | - (void)drawRect:(CGRect)rect { 26 | // Drawing code 27 | if (self.numberOfLines != 1 || _icon == nil) { 28 | [super drawTextInRect:rect]; 29 | return; 30 | } 31 | 32 | if (_icon != nil) { 33 | [_iconView removeFromSuperview]; 34 | _iconView = [[UIImageView alloc] initWithImage:_icon]; 35 | 36 | CGRect newRect = CGRectZero; 37 | CGSize size = self.frame.size; 38 | 39 | size = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, self.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:self.font forKey:NSFontAttributeName] context:nil].size; 40 | 41 | if (_iconView != nil) { 42 | 43 | if (_iconPosition == ZLIconLabelPositionLeft) { 44 | 45 | if (self.textAlignment == NSTextAlignmentLeft) { 46 | _iconView.frame = CGRectOffset(_iconView.frame, 0, (self.height - _iconView.height) / 2); 47 | newRect = CGRectMake(_iconView.width + _iconPadding, 0, self.width - (_iconView.width + _iconPadding), self.height); 48 | } else if (self.textAlignment == NSTextAlignmentRight) { 49 | _iconView.frame = CGRectOffset(_iconView.frame, self.width - size.width - _iconView.width - _iconPadding, (self.height - _iconView.height) / 2); 50 | newRect = CGRectMake(self.width - size.width - _iconPadding, 0, size.width + _iconPadding, self.height); 51 | } else if (self.textAlignment == NSTextAlignmentCenter) { 52 | _iconView.frame = CGRectOffset(_iconView.frame, (self.width - size.width) / 2 - _iconPadding - _iconView.width, (self.height - _iconView.height) / 2); 53 | newRect = CGRectMake((self.width - size.width) / 2, 0, size.width + _iconPadding, self.height); 54 | } 55 | 56 | } else if (_iconPosition == ZLIconLabelPositionRight) { 57 | 58 | if (self.textAlignment == NSTextAlignmentLeft) { 59 | _iconView.frame = CGRectOffset(_iconView.frame, size.width + _iconPadding, (self.height - _iconView.height) / 2); 60 | newRect = CGRectMake(0, 0, self.width - self.width, self.height); 61 | } else if (self.textAlignment == NSTextAlignmentRight) { 62 | _iconView.frame = CGRectOffset(_iconView.frame, self.width - _iconView.width, (self.height - _iconView.height) / 2); 63 | newRect = CGRectMake(self.width - size.width - _iconView.width - _iconPadding, 0, size.width, self.height); 64 | } else if (self.textAlignment == NSTextAlignmentCenter) { 65 | _iconView.frame = CGRectOffset(_iconView.frame, self.width / 2 + size.width / 2 + _iconPadding, (self.height - _iconView.self.height) / 2); 66 | newRect = CGRectMake((self.width - size.width) / 2, 0, size.width, self.height); 67 | } 68 | 69 | } 70 | [self addSubview:_iconView]; 71 | [super drawTextInRect:newRect]; 72 | } 73 | } 74 | 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /ZLIconLabel/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZLIconLabel 4 | // 5 | // Created by apple on 16/4/11. 6 | // Copyright © 2016年 ANGELEN. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------