├── README.md ├── UIButton+Layout.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── UIButton+Layout ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── wx.imageset │ │ ├── Contents.json │ │ └── wx.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Category │ ├── UIButton+Layout.h │ └── UIButton+Layout.m ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── UIButton+LayoutTests ├── Info.plist └── UIButton_LayoutTests.m └── UIButton+LayoutUITests ├── Info.plist └── UIButton_LayoutUITests.m /README.md: -------------------------------------------------------------------------------- 1 | # UIButton-Layout 2 | 左文右图、上图下文 3 | 4 | 实现UIButton图片、文字的自定义布局 5 | 6 | 调用方法: 7 | 8 | - (void)setImageLayout:(UIButtonLayoutType)type space:(CGFloat)space; 9 | -------------------------------------------------------------------------------- /UIButton+Layout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 364A62BB209B1F5100E67B90 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62BA209B1F5100E67B90 /* AppDelegate.m */; }; 11 | 364A62BE209B1F5100E67B90 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62BD209B1F5100E67B90 /* ViewController.m */; }; 12 | 364A62C1209B1F5100E67B90 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 364A62BF209B1F5100E67B90 /* Main.storyboard */; }; 13 | 364A62C3209B1F5100E67B90 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 364A62C2209B1F5100E67B90 /* Assets.xcassets */; }; 14 | 364A62C6209B1F5100E67B90 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 364A62C4209B1F5100E67B90 /* LaunchScreen.storyboard */; }; 15 | 364A62C9209B1F5100E67B90 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62C8209B1F5100E67B90 /* main.m */; }; 16 | 364A62D3209B1F5100E67B90 /* UIButton_LayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62D2209B1F5100E67B90 /* UIButton_LayoutTests.m */; }; 17 | 364A62DE209B1F5100E67B90 /* UIButton_LayoutUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62DD209B1F5100E67B90 /* UIButton_LayoutUITests.m */; }; 18 | 364A62EE209B1FAE00E67B90 /* UIButton+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 364A62ED209B1FAE00E67B90 /* UIButton+Layout.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 364A62CF209B1F5100E67B90 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 364A62AE209B1F5100E67B90 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 364A62B5209B1F5100E67B90; 27 | remoteInfo = "UIButton+Layout"; 28 | }; 29 | 364A62DA209B1F5100E67B90 /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 364A62AE209B1F5100E67B90 /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 364A62B5209B1F5100E67B90; 34 | remoteInfo = "UIButton+Layout"; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 364A62B6209B1F5100E67B90 /* UIButton+Layout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "UIButton+Layout.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 364A62B9209B1F5100E67B90 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 41 | 364A62BA209B1F5100E67B90 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 42 | 364A62BC209B1F5100E67B90 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 43 | 364A62BD209B1F5100E67B90 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 44 | 364A62C0209B1F5100E67B90 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 45 | 364A62C2209B1F5100E67B90 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 46 | 364A62C5209B1F5100E67B90 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 47 | 364A62C7209B1F5100E67B90 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 364A62C8209B1F5100E67B90 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 49 | 364A62CE209B1F5100E67B90 /* UIButton+LayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UIButton+LayoutTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 364A62D2209B1F5100E67B90 /* UIButton_LayoutTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIButton_LayoutTests.m; sourceTree = ""; }; 51 | 364A62D4209B1F5100E67B90 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 364A62D9209B1F5100E67B90 /* UIButton+LayoutUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UIButton+LayoutUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 364A62DD209B1F5100E67B90 /* UIButton_LayoutUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIButton_LayoutUITests.m; sourceTree = ""; }; 54 | 364A62DF209B1F5100E67B90 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 364A62EC209B1FAE00E67B90 /* UIButton+Layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+Layout.h"; sourceTree = ""; }; 56 | 364A62ED209B1FAE00E67B90 /* UIButton+Layout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+Layout.m"; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 364A62B3209B1F5100E67B90 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 364A62CB209B1F5100E67B90 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 364A62D6209B1F5100E67B90 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | 364A62AD209B1F5100E67B90 = { 85 | isa = PBXGroup; 86 | children = ( 87 | 364A62B8209B1F5100E67B90 /* UIButton+Layout */, 88 | 364A62D1209B1F5100E67B90 /* UIButton+LayoutTests */, 89 | 364A62DC209B1F5100E67B90 /* UIButton+LayoutUITests */, 90 | 364A62B7209B1F5100E67B90 /* Products */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 364A62B7209B1F5100E67B90 /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 364A62B6209B1F5100E67B90 /* UIButton+Layout.app */, 98 | 364A62CE209B1F5100E67B90 /* UIButton+LayoutTests.xctest */, 99 | 364A62D9209B1F5100E67B90 /* UIButton+LayoutUITests.xctest */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | 364A62B8209B1F5100E67B90 /* UIButton+Layout */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 364A62EB209B1FAE00E67B90 /* Category */, 108 | 364A62B9209B1F5100E67B90 /* AppDelegate.h */, 109 | 364A62BA209B1F5100E67B90 /* AppDelegate.m */, 110 | 364A62BC209B1F5100E67B90 /* ViewController.h */, 111 | 364A62BD209B1F5100E67B90 /* ViewController.m */, 112 | 364A62BF209B1F5100E67B90 /* Main.storyboard */, 113 | 364A62C2209B1F5100E67B90 /* Assets.xcassets */, 114 | 364A62C4209B1F5100E67B90 /* LaunchScreen.storyboard */, 115 | 364A62C7209B1F5100E67B90 /* Info.plist */, 116 | 364A62C8209B1F5100E67B90 /* main.m */, 117 | ); 118 | path = "UIButton+Layout"; 119 | sourceTree = ""; 120 | }; 121 | 364A62D1209B1F5100E67B90 /* UIButton+LayoutTests */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 364A62D2209B1F5100E67B90 /* UIButton_LayoutTests.m */, 125 | 364A62D4209B1F5100E67B90 /* Info.plist */, 126 | ); 127 | path = "UIButton+LayoutTests"; 128 | sourceTree = ""; 129 | }; 130 | 364A62DC209B1F5100E67B90 /* UIButton+LayoutUITests */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 364A62DD209B1F5100E67B90 /* UIButton_LayoutUITests.m */, 134 | 364A62DF209B1F5100E67B90 /* Info.plist */, 135 | ); 136 | path = "UIButton+LayoutUITests"; 137 | sourceTree = ""; 138 | }; 139 | 364A62EB209B1FAE00E67B90 /* Category */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 364A62EC209B1FAE00E67B90 /* UIButton+Layout.h */, 143 | 364A62ED209B1FAE00E67B90 /* UIButton+Layout.m */, 144 | ); 145 | path = Category; 146 | sourceTree = ""; 147 | }; 148 | /* End PBXGroup section */ 149 | 150 | /* Begin PBXNativeTarget section */ 151 | 364A62B5209B1F5100E67B90 /* UIButton+Layout */ = { 152 | isa = PBXNativeTarget; 153 | buildConfigurationList = 364A62E2209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+Layout" */; 154 | buildPhases = ( 155 | 364A62B2209B1F5100E67B90 /* Sources */, 156 | 364A62B3209B1F5100E67B90 /* Frameworks */, 157 | 364A62B4209B1F5100E67B90 /* Resources */, 158 | ); 159 | buildRules = ( 160 | ); 161 | dependencies = ( 162 | ); 163 | name = "UIButton+Layout"; 164 | productName = "UIButton+Layout"; 165 | productReference = 364A62B6209B1F5100E67B90 /* UIButton+Layout.app */; 166 | productType = "com.apple.product-type.application"; 167 | }; 168 | 364A62CD209B1F5100E67B90 /* UIButton+LayoutTests */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = 364A62E5209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+LayoutTests" */; 171 | buildPhases = ( 172 | 364A62CA209B1F5100E67B90 /* Sources */, 173 | 364A62CB209B1F5100E67B90 /* Frameworks */, 174 | 364A62CC209B1F5100E67B90 /* Resources */, 175 | ); 176 | buildRules = ( 177 | ); 178 | dependencies = ( 179 | 364A62D0209B1F5100E67B90 /* PBXTargetDependency */, 180 | ); 181 | name = "UIButton+LayoutTests"; 182 | productName = "UIButton+LayoutTests"; 183 | productReference = 364A62CE209B1F5100E67B90 /* UIButton+LayoutTests.xctest */; 184 | productType = "com.apple.product-type.bundle.unit-test"; 185 | }; 186 | 364A62D8209B1F5100E67B90 /* UIButton+LayoutUITests */ = { 187 | isa = PBXNativeTarget; 188 | buildConfigurationList = 364A62E8209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+LayoutUITests" */; 189 | buildPhases = ( 190 | 364A62D5209B1F5100E67B90 /* Sources */, 191 | 364A62D6209B1F5100E67B90 /* Frameworks */, 192 | 364A62D7209B1F5100E67B90 /* Resources */, 193 | ); 194 | buildRules = ( 195 | ); 196 | dependencies = ( 197 | 364A62DB209B1F5100E67B90 /* PBXTargetDependency */, 198 | ); 199 | name = "UIButton+LayoutUITests"; 200 | productName = "UIButton+LayoutUITests"; 201 | productReference = 364A62D9209B1F5100E67B90 /* UIButton+LayoutUITests.xctest */; 202 | productType = "com.apple.product-type.bundle.ui-testing"; 203 | }; 204 | /* End PBXNativeTarget section */ 205 | 206 | /* Begin PBXProject section */ 207 | 364A62AE209B1F5100E67B90 /* Project object */ = { 208 | isa = PBXProject; 209 | attributes = { 210 | LastUpgradeCheck = 0920; 211 | ORGANIZATIONNAME = lzy; 212 | TargetAttributes = { 213 | 364A62B5209B1F5100E67B90 = { 214 | CreatedOnToolsVersion = 9.2; 215 | ProvisioningStyle = Automatic; 216 | }; 217 | 364A62CD209B1F5100E67B90 = { 218 | CreatedOnToolsVersion = 9.2; 219 | ProvisioningStyle = Automatic; 220 | TestTargetID = 364A62B5209B1F5100E67B90; 221 | }; 222 | 364A62D8209B1F5100E67B90 = { 223 | CreatedOnToolsVersion = 9.2; 224 | ProvisioningStyle = Automatic; 225 | TestTargetID = 364A62B5209B1F5100E67B90; 226 | }; 227 | }; 228 | }; 229 | buildConfigurationList = 364A62B1209B1F5100E67B90 /* Build configuration list for PBXProject "UIButton+Layout" */; 230 | compatibilityVersion = "Xcode 8.0"; 231 | developmentRegion = en; 232 | hasScannedForEncodings = 0; 233 | knownRegions = ( 234 | en, 235 | Base, 236 | ); 237 | mainGroup = 364A62AD209B1F5100E67B90; 238 | productRefGroup = 364A62B7209B1F5100E67B90 /* Products */; 239 | projectDirPath = ""; 240 | projectRoot = ""; 241 | targets = ( 242 | 364A62B5209B1F5100E67B90 /* UIButton+Layout */, 243 | 364A62CD209B1F5100E67B90 /* UIButton+LayoutTests */, 244 | 364A62D8209B1F5100E67B90 /* UIButton+LayoutUITests */, 245 | ); 246 | }; 247 | /* End PBXProject section */ 248 | 249 | /* Begin PBXResourcesBuildPhase section */ 250 | 364A62B4209B1F5100E67B90 /* Resources */ = { 251 | isa = PBXResourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | 364A62C6209B1F5100E67B90 /* LaunchScreen.storyboard in Resources */, 255 | 364A62C3209B1F5100E67B90 /* Assets.xcassets in Resources */, 256 | 364A62C1209B1F5100E67B90 /* Main.storyboard in Resources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | 364A62CC209B1F5100E67B90 /* Resources */ = { 261 | isa = PBXResourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | 364A62D7209B1F5100E67B90 /* Resources */ = { 268 | isa = PBXResourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | /* End PBXResourcesBuildPhase section */ 275 | 276 | /* Begin PBXSourcesBuildPhase section */ 277 | 364A62B2209B1F5100E67B90 /* Sources */ = { 278 | isa = PBXSourcesBuildPhase; 279 | buildActionMask = 2147483647; 280 | files = ( 281 | 364A62BE209B1F5100E67B90 /* ViewController.m in Sources */, 282 | 364A62C9209B1F5100E67B90 /* main.m in Sources */, 283 | 364A62BB209B1F5100E67B90 /* AppDelegate.m in Sources */, 284 | 364A62EE209B1FAE00E67B90 /* UIButton+Layout.m in Sources */, 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | 364A62CA209B1F5100E67B90 /* Sources */ = { 289 | isa = PBXSourcesBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | 364A62D3209B1F5100E67B90 /* UIButton_LayoutTests.m in Sources */, 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | 364A62D5209B1F5100E67B90 /* Sources */ = { 297 | isa = PBXSourcesBuildPhase; 298 | buildActionMask = 2147483647; 299 | files = ( 300 | 364A62DE209B1F5100E67B90 /* UIButton_LayoutUITests.m in Sources */, 301 | ); 302 | runOnlyForDeploymentPostprocessing = 0; 303 | }; 304 | /* End PBXSourcesBuildPhase section */ 305 | 306 | /* Begin PBXTargetDependency section */ 307 | 364A62D0209B1F5100E67B90 /* PBXTargetDependency */ = { 308 | isa = PBXTargetDependency; 309 | target = 364A62B5209B1F5100E67B90 /* UIButton+Layout */; 310 | targetProxy = 364A62CF209B1F5100E67B90 /* PBXContainerItemProxy */; 311 | }; 312 | 364A62DB209B1F5100E67B90 /* PBXTargetDependency */ = { 313 | isa = PBXTargetDependency; 314 | target = 364A62B5209B1F5100E67B90 /* UIButton+Layout */; 315 | targetProxy = 364A62DA209B1F5100E67B90 /* PBXContainerItemProxy */; 316 | }; 317 | /* End PBXTargetDependency section */ 318 | 319 | /* Begin PBXVariantGroup section */ 320 | 364A62BF209B1F5100E67B90 /* Main.storyboard */ = { 321 | isa = PBXVariantGroup; 322 | children = ( 323 | 364A62C0209B1F5100E67B90 /* Base */, 324 | ); 325 | name = Main.storyboard; 326 | sourceTree = ""; 327 | }; 328 | 364A62C4209B1F5100E67B90 /* LaunchScreen.storyboard */ = { 329 | isa = PBXVariantGroup; 330 | children = ( 331 | 364A62C5209B1F5100E67B90 /* Base */, 332 | ); 333 | name = LaunchScreen.storyboard; 334 | sourceTree = ""; 335 | }; 336 | /* End PBXVariantGroup section */ 337 | 338 | /* Begin XCBuildConfiguration section */ 339 | 364A62E0209B1F5100E67B90 /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_SEARCH_USER_PATHS = NO; 343 | CLANG_ANALYZER_NONNULL = YES; 344 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 345 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 346 | CLANG_CXX_LIBRARY = "libc++"; 347 | CLANG_ENABLE_MODULES = YES; 348 | CLANG_ENABLE_OBJC_ARC = YES; 349 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 350 | CLANG_WARN_BOOL_CONVERSION = YES; 351 | CLANG_WARN_COMMA = YES; 352 | CLANG_WARN_CONSTANT_CONVERSION = YES; 353 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 354 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 355 | CLANG_WARN_EMPTY_BODY = YES; 356 | CLANG_WARN_ENUM_CONVERSION = YES; 357 | CLANG_WARN_INFINITE_RECURSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 360 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 361 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 362 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 363 | CLANG_WARN_STRICT_PROTOTYPES = YES; 364 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 365 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 366 | CLANG_WARN_UNREACHABLE_CODE = YES; 367 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 368 | CODE_SIGN_IDENTITY = "iPhone Developer"; 369 | COPY_PHASE_STRIP = NO; 370 | DEBUG_INFORMATION_FORMAT = dwarf; 371 | ENABLE_STRICT_OBJC_MSGSEND = YES; 372 | ENABLE_TESTABILITY = YES; 373 | GCC_C_LANGUAGE_STANDARD = gnu11; 374 | GCC_DYNAMIC_NO_PIC = NO; 375 | GCC_NO_COMMON_BLOCKS = YES; 376 | GCC_OPTIMIZATION_LEVEL = 0; 377 | GCC_PREPROCESSOR_DEFINITIONS = ( 378 | "DEBUG=1", 379 | "$(inherited)", 380 | ); 381 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 382 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 383 | GCC_WARN_UNDECLARED_SELECTOR = YES; 384 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 385 | GCC_WARN_UNUSED_FUNCTION = YES; 386 | GCC_WARN_UNUSED_VARIABLE = YES; 387 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 388 | MTL_ENABLE_DEBUG_INFO = YES; 389 | ONLY_ACTIVE_ARCH = YES; 390 | SDKROOT = iphoneos; 391 | }; 392 | name = Debug; 393 | }; 394 | 364A62E1209B1F5100E67B90 /* Release */ = { 395 | isa = XCBuildConfiguration; 396 | buildSettings = { 397 | ALWAYS_SEARCH_USER_PATHS = NO; 398 | CLANG_ANALYZER_NONNULL = YES; 399 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 400 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 401 | CLANG_CXX_LIBRARY = "libc++"; 402 | CLANG_ENABLE_MODULES = YES; 403 | CLANG_ENABLE_OBJC_ARC = YES; 404 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 405 | CLANG_WARN_BOOL_CONVERSION = YES; 406 | CLANG_WARN_COMMA = YES; 407 | CLANG_WARN_CONSTANT_CONVERSION = YES; 408 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 409 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 410 | CLANG_WARN_EMPTY_BODY = YES; 411 | CLANG_WARN_ENUM_CONVERSION = YES; 412 | CLANG_WARN_INFINITE_RECURSION = YES; 413 | CLANG_WARN_INT_CONVERSION = YES; 414 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 415 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 416 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 417 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 418 | CLANG_WARN_STRICT_PROTOTYPES = YES; 419 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 420 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 421 | CLANG_WARN_UNREACHABLE_CODE = YES; 422 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 423 | CODE_SIGN_IDENTITY = "iPhone Developer"; 424 | COPY_PHASE_STRIP = NO; 425 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 426 | ENABLE_NS_ASSERTIONS = NO; 427 | ENABLE_STRICT_OBJC_MSGSEND = YES; 428 | GCC_C_LANGUAGE_STANDARD = gnu11; 429 | GCC_NO_COMMON_BLOCKS = YES; 430 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 431 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 432 | GCC_WARN_UNDECLARED_SELECTOR = YES; 433 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 434 | GCC_WARN_UNUSED_FUNCTION = YES; 435 | GCC_WARN_UNUSED_VARIABLE = YES; 436 | IPHONEOS_DEPLOYMENT_TARGET = 11.2; 437 | MTL_ENABLE_DEBUG_INFO = NO; 438 | SDKROOT = iphoneos; 439 | VALIDATE_PRODUCT = YES; 440 | }; 441 | name = Release; 442 | }; 443 | 364A62E3209B1F5100E67B90 /* Debug */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 447 | CODE_SIGN_STYLE = Automatic; 448 | DEVELOPMENT_TEAM = WVNM4ESZ25; 449 | INFOPLIST_FILE = "UIButton+Layout/Info.plist"; 450 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 451 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-Layout"; 452 | PRODUCT_NAME = "$(TARGET_NAME)"; 453 | TARGETED_DEVICE_FAMILY = "1,2"; 454 | }; 455 | name = Debug; 456 | }; 457 | 364A62E4209B1F5100E67B90 /* Release */ = { 458 | isa = XCBuildConfiguration; 459 | buildSettings = { 460 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 461 | CODE_SIGN_STYLE = Automatic; 462 | DEVELOPMENT_TEAM = WVNM4ESZ25; 463 | INFOPLIST_FILE = "UIButton+Layout/Info.plist"; 464 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 465 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-Layout"; 466 | PRODUCT_NAME = "$(TARGET_NAME)"; 467 | TARGETED_DEVICE_FAMILY = "1,2"; 468 | }; 469 | name = Release; 470 | }; 471 | 364A62E6209B1F5100E67B90 /* Debug */ = { 472 | isa = XCBuildConfiguration; 473 | buildSettings = { 474 | BUNDLE_LOADER = "$(TEST_HOST)"; 475 | CODE_SIGN_STYLE = Automatic; 476 | DEVELOPMENT_TEAM = WVNM4ESZ25; 477 | INFOPLIST_FILE = "UIButton+LayoutTests/Info.plist"; 478 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 479 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-LayoutTests"; 480 | PRODUCT_NAME = "$(TARGET_NAME)"; 481 | TARGETED_DEVICE_FAMILY = "1,2"; 482 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UIButton+Layout.app/UIButton+Layout"; 483 | }; 484 | name = Debug; 485 | }; 486 | 364A62E7209B1F5100E67B90 /* Release */ = { 487 | isa = XCBuildConfiguration; 488 | buildSettings = { 489 | BUNDLE_LOADER = "$(TEST_HOST)"; 490 | CODE_SIGN_STYLE = Automatic; 491 | DEVELOPMENT_TEAM = WVNM4ESZ25; 492 | INFOPLIST_FILE = "UIButton+LayoutTests/Info.plist"; 493 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 494 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-LayoutTests"; 495 | PRODUCT_NAME = "$(TARGET_NAME)"; 496 | TARGETED_DEVICE_FAMILY = "1,2"; 497 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UIButton+Layout.app/UIButton+Layout"; 498 | }; 499 | name = Release; 500 | }; 501 | 364A62E9209B1F5100E67B90 /* Debug */ = { 502 | isa = XCBuildConfiguration; 503 | buildSettings = { 504 | CODE_SIGN_STYLE = Automatic; 505 | DEVELOPMENT_TEAM = WVNM4ESZ25; 506 | INFOPLIST_FILE = "UIButton+LayoutUITests/Info.plist"; 507 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 508 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-LayoutUITests"; 509 | PRODUCT_NAME = "$(TARGET_NAME)"; 510 | TARGETED_DEVICE_FAMILY = "1,2"; 511 | TEST_TARGET_NAME = "UIButton+Layout"; 512 | }; 513 | name = Debug; 514 | }; 515 | 364A62EA209B1F5100E67B90 /* Release */ = { 516 | isa = XCBuildConfiguration; 517 | buildSettings = { 518 | CODE_SIGN_STYLE = Automatic; 519 | DEVELOPMENT_TEAM = WVNM4ESZ25; 520 | INFOPLIST_FILE = "UIButton+LayoutUITests/Info.plist"; 521 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 522 | PRODUCT_BUNDLE_IDENTIFIER = "com.zuzuche.UIButton-LayoutUITests"; 523 | PRODUCT_NAME = "$(TARGET_NAME)"; 524 | TARGETED_DEVICE_FAMILY = "1,2"; 525 | TEST_TARGET_NAME = "UIButton+Layout"; 526 | }; 527 | name = Release; 528 | }; 529 | /* End XCBuildConfiguration section */ 530 | 531 | /* Begin XCConfigurationList section */ 532 | 364A62B1209B1F5100E67B90 /* Build configuration list for PBXProject "UIButton+Layout" */ = { 533 | isa = XCConfigurationList; 534 | buildConfigurations = ( 535 | 364A62E0209B1F5100E67B90 /* Debug */, 536 | 364A62E1209B1F5100E67B90 /* Release */, 537 | ); 538 | defaultConfigurationIsVisible = 0; 539 | defaultConfigurationName = Release; 540 | }; 541 | 364A62E2209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+Layout" */ = { 542 | isa = XCConfigurationList; 543 | buildConfigurations = ( 544 | 364A62E3209B1F5100E67B90 /* Debug */, 545 | 364A62E4209B1F5100E67B90 /* Release */, 546 | ); 547 | defaultConfigurationIsVisible = 0; 548 | defaultConfigurationName = Release; 549 | }; 550 | 364A62E5209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+LayoutTests" */ = { 551 | isa = XCConfigurationList; 552 | buildConfigurations = ( 553 | 364A62E6209B1F5100E67B90 /* Debug */, 554 | 364A62E7209B1F5100E67B90 /* Release */, 555 | ); 556 | defaultConfigurationIsVisible = 0; 557 | defaultConfigurationName = Release; 558 | }; 559 | 364A62E8209B1F5100E67B90 /* Build configuration list for PBXNativeTarget "UIButton+LayoutUITests" */ = { 560 | isa = XCConfigurationList; 561 | buildConfigurations = ( 562 | 364A62E9209B1F5100E67B90 /* Debug */, 563 | 364A62EA209B1F5100E67B90 /* Release */, 564 | ); 565 | defaultConfigurationIsVisible = 0; 566 | defaultConfigurationName = Release; 567 | }; 568 | /* End XCConfigurationList section */ 569 | }; 570 | rootObject = 364A62AE209B1F5100E67B90 /* Project object */; 571 | } 572 | -------------------------------------------------------------------------------- /UIButton+Layout.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIButton+Layout/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // UIButton+Layout 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. 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 | -------------------------------------------------------------------------------- /UIButton+Layout/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // UIButton+Layout 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. 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 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /UIButton+Layout/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 | } -------------------------------------------------------------------------------- /UIButton+Layout/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /UIButton+Layout/Assets.xcassets/wx.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "wx.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /UIButton+Layout/Assets.xcassets/wx.imageset/wx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzy1010/UIButton-Layout/72183a45d95525b0cc431e09ed6eb1ae27a4ea6d/UIButton+Layout/Assets.xcassets/wx.imageset/wx.png -------------------------------------------------------------------------------- /UIButton+Layout/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 | -------------------------------------------------------------------------------- /UIButton+Layout/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 | -------------------------------------------------------------------------------- /UIButton+Layout/Category/UIButton+Layout.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Layout.h 3 | // SDLBtn 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, UIButtonLayoutType) { 12 | UIButtonLayoutImageLeft, 13 | UIButtonLayoutImageRight, 14 | UIButtonLayoutImageTop, 15 | UIButtonLayoutImageBottom, 16 | }; 17 | 18 | @interface UIButton (Layout) 19 | 20 | - (void)setImageLayout:(UIButtonLayoutType)type space:(CGFloat)space; 21 | 22 | /** 23 | titleLabel是否自适应宽度 24 | */ 25 | @property (assign, nonatomic) BOOL isSizeToFit; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /UIButton+Layout/Category/UIButton+Layout.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Layout.m 3 | // SDLBtn 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import "UIButton+Layout.h" 10 | #import 11 | 12 | static void *infoDicKey = &infoDicKey; 13 | 14 | @interface UIButton () 15 | 16 | @property (strong, nonatomic) NSMutableDictionary *infoDic; 17 | @property (assign, nonatomic) UIButtonLayoutType type; 18 | @property (assign, nonatomic) CGFloat space; 19 | @property (assign, nonatomic) BOOL support; 20 | 21 | @end 22 | 23 | @implementation UIButton (Layout) 24 | 25 | + (void)load{ 26 | Method newMethod = class_getInstanceMethod([self class], @selector(lzyLayoutSubviews)); 27 | Method method = class_getInstanceMethod([self class], @selector(layoutSubviews)); 28 | method_exchangeImplementations(newMethod, method); 29 | } 30 | 31 | - (void)setImageLayout:(UIButtonLayoutType)type space:(CGFloat)space{ 32 | [self.infoDic setValue:@(type) forKey:@"type"]; 33 | [self.infoDic setValue:@(space) forKey:@"space"]; 34 | [self.infoDic setValue:@true forKey:@"support"]; 35 | 36 | objc_setAssociatedObject(self, &infoDicKey, self.infoDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 37 | } 38 | 39 | - (void)lzyLayoutSubviews{ 40 | 41 | [self lzyLayoutSubviews]; 42 | 43 | if (!self.support) { 44 | if (self.isSizeToFit) { 45 | [self.titleLabel sizeToFit]; 46 | } 47 | return; 48 | } 49 | 50 | UIButtonLayoutType type = self.type; 51 | CGFloat space = self.space; 52 | 53 | CGSize titleSize = self.titleLabel.bounds.size; 54 | CGSize imageSize = self.imageView.frame.size; 55 | 56 | CGFloat fitOffset = 0; 57 | if (self.isSizeToFit) { 58 | [self.titleLabel sizeToFit]; 59 | CGSize fitTitleSize = self.titleLabel.bounds.size; 60 | fitOffset = fitTitleSize.width - titleSize.width; 61 | } 62 | 63 | CGFloat spaceOffset = space/2.0; 64 | 65 | CGFloat imageWidthOffset = titleSize.width/2.0; 66 | CGFloat imageHeightOffset = titleSize.height/2.0; 67 | CGFloat titleWidthOffset = imageSize.width/2.0 + fitOffset/2.0; 68 | CGFloat titleHeightOffset = imageSize.height/2.0; 69 | 70 | switch (type) { 71 | case UIButtonLayoutImageTop: 72 | self.titleEdgeInsets = UIEdgeInsetsMake(titleHeightOffset+space, -titleWidthOffset, -titleHeightOffset-spaceOffset, +titleWidthOffset); 73 | self.imageEdgeInsets = UIEdgeInsetsMake(-imageHeightOffset-spaceOffset, imageWidthOffset, imageHeightOffset+spaceOffset, -imageWidthOffset); 74 | break; 75 | case UIButtonLayoutImageBottom: 76 | self.titleEdgeInsets = UIEdgeInsetsMake(-titleHeightOffset-spaceOffset, -titleWidthOffset, titleHeightOffset+spaceOffset, titleWidthOffset); 77 | self.imageEdgeInsets = UIEdgeInsetsMake(imageHeightOffset+spaceOffset, imageWidthOffset, -imageHeightOffset-spaceOffset, -imageWidthOffset); 78 | break; 79 | case UIButtonLayoutImageLeft: 80 | self.titleEdgeInsets = UIEdgeInsetsMake(0, spaceOffset, 0, -spaceOffset); 81 | self.imageEdgeInsets = UIEdgeInsetsMake(0, -spaceOffset, 0, spaceOffset); 82 | break; 83 | case UIButtonLayoutImageRight: 84 | self.titleEdgeInsets = UIEdgeInsetsMake(0, -2*titleWidthOffset - spaceOffset, 0, 2*titleWidthOffset + spaceOffset); 85 | self.imageEdgeInsets = UIEdgeInsetsMake(0, 2*imageWidthOffset + spaceOffset, 0, -2*imageWidthOffset - spaceOffset); 86 | break; 87 | default: 88 | break; 89 | } 90 | } 91 | 92 | - (void)setIsSizeToFit:(BOOL)isSizeToFit{ 93 | [self.infoDic setValue:@(isSizeToFit) forKey:@"isSizeToFit"]; 94 | objc_setAssociatedObject(self, &infoDicKey, self.infoDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 95 | } 96 | 97 | - (BOOL)isSizeToFit{ 98 | return [self.infoDic[@"isSizeToFit"] boolValue]; 99 | } 100 | 101 | - (CGFloat)space{ 102 | return [self.infoDic[@"space"] floatValue]; 103 | } 104 | 105 | - (UIButtonLayoutType)type{ 106 | return (UIButtonLayoutType)[self.infoDic[@"type"] integerValue]; 107 | } 108 | 109 | - (BOOL)support{ 110 | return [self.infoDic[@"support"] boolValue]; 111 | } 112 | 113 | - (NSMutableDictionary *)infoDic{ 114 | NSMutableDictionary *infoDic = objc_getAssociatedObject(self, &infoDicKey); 115 | if (!infoDic) { 116 | infoDic = [@{@"type":@(UIButtonLayoutImageLeft),@"space":@0,@"isSizeToFit":@false,@"support":@false} mutableCopy]; 117 | objc_setAssociatedObject(self, &infoDicKey, infoDic, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 118 | } 119 | 120 | return infoDic; 121 | } 122 | 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /UIButton+Layout/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 | -------------------------------------------------------------------------------- /UIButton+Layout/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // UIButton+Layout 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /UIButton+Layout/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // UIButton+Layout 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "UIButton+Layout.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (strong, nonatomic) UIButton *SDLBtn; 15 | 16 | @end 17 | 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.SDLBtn = ({ 24 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 25 | [btn setBackgroundColor:[UIColor cyanColor]]; 26 | 27 | [btn setImage:[UIImage imageNamed:@"wx"] forState:UIControlStateNormal]; 28 | [btn setImage:[UIImage imageNamed:@"wx"] forState:UIControlStateNormal]; 29 | [btn setTitle:@"哈哈哈haha\nha" forState:UIControlStateNormal]; 30 | [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 31 | btn.titleLabel.font = [UIFont systemFontOfSize:25]; 32 | 33 | [btn setImageLayout:UIButtonLayoutImageBottom space:10]; 34 | btn.isSizeToFit = true; 35 | 36 | btn; 37 | }); 38 | 39 | [self.view addSubview:self.SDLBtn]; 40 | 41 | self.SDLBtn.frame = CGRectMake(100, 100, 200, 200); 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /UIButton+Layout/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UIButton+Layout 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. 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 | -------------------------------------------------------------------------------- /UIButton+LayoutTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIButton+LayoutTests/UIButton_LayoutTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton_LayoutTests.m 3 | // UIButton+LayoutTests 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIButton_LayoutTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UIButton_LayoutTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /UIButton+LayoutUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIButton+LayoutUITests/UIButton_LayoutUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton_LayoutUITests.m 3 | // UIButton+LayoutUITests 4 | // 5 | // Created by zzc-13 on 2018/5/3. 6 | // Copyright © 2018年 lzy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIButton_LayoutUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UIButton_LayoutUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------