├── README.md ├── ZPRankButton.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── ZPRankButton.xccheckout │ └── xcuserdata │ │ └── zhengpeng.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── zhengpeng.xcuserdatad │ └── xcschemes │ ├── ZPRankButton.xcscheme │ └── xcschememanagement.plist ├── ZPRankButton ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m ├── ZPButtonRank │ ├── RankButton.h │ └── RankButton.m ├── main.m ├── mall_dingzhi@2x.png └── mall_leimu@2x.png ├── ZPRankButtonTests ├── Info.plist └── ZPRankButtonTests.m └── 效果图.png /README.md: -------------------------------------------------------------------------------- 1 | # ZPRankButton 2 | 3 | 一款继承UIButton的button封装类,可以一个参数实现图文任意排列,一个参数实现图片文字距离边缘的距离,一个参数实现图文间距 4 | 5 | 6 | typedef enum : NSUInteger { 7 | 8 | buttonTypeNormal, //默认 左边图 右边文字 (可不写) 9 | 10 | buttonTypePicTop, // 图片在上面 文字在下面 11 | 12 | buttonTypePicRight, // 图片在右边 文字在左边 13 | 14 | buttonTypePictBottom //文字在上面 图片在下面 15 | 16 | } ButtonType; 17 | 18 | typedef enum : NSUInteger { 19 | 20 | buttonAlignWithNormal, //默认 (可不写) 21 | 22 | buttonAlignWithPic, //以图片为基准进行调整距离边缘的位置 23 | 24 | buttonAlignWithTitle //以文字为基准进行调整距离边缘的位置 25 | 26 | } ButtonAlignType; //图文排版(只做了图文左右排列的支持 上下排列的整体位置调整 后期加) 27 | 28 | 29 | @interface RankButton : UIButton 30 | 31 | @property (nonatomic,assign) ButtonType type; 32 | 33 | @property (nonatomic,assign) ButtonAlignType alignType; 34 | 35 | //图片文字之间的间距 36 | 37 | @property (nonatomic,assign) NSInteger picTileRange; 38 | 39 | //以图片为基准,设置图片距离边缘的位置 40 | 41 | @property (nonatomic,assign) NSInteger picToViewRange; 42 | 43 | ![image](https://github.com/GeekZP/ZPRankButton/blob/master/效果图.png) 44 | -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7E56E50D1B326398002D0A73 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56E50C1B326398002D0A73 /* main.m */; }; 11 | 7E56E5101B326398002D0A73 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56E50F1B326398002D0A73 /* AppDelegate.m */; }; 12 | 7E56E5131B326398002D0A73 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56E5121B326398002D0A73 /* ViewController.m */; }; 13 | 7E56E5161B326398002D0A73 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7E56E5141B326398002D0A73 /* Main.storyboard */; }; 14 | 7E56E5181B326398002D0A73 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7E56E5171B326398002D0A73 /* Images.xcassets */; }; 15 | 7E56E51B1B326398002D0A73 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7E56E5191B326398002D0A73 /* LaunchScreen.xib */; }; 16 | 7E56E5271B326398002D0A73 /* ZPRankButtonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56E5261B326398002D0A73 /* ZPRankButtonTests.m */; }; 17 | 7E56E5451B3269A3002D0A73 /* mall_dingzhi@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7E56E5401B3269A3002D0A73 /* mall_dingzhi@2x.png */; }; 18 | 7E56E5461B3269A3002D0A73 /* mall_leimu@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7E56E5411B3269A3002D0A73 /* mall_leimu@2x.png */; }; 19 | 7E56E5471B3269A3002D0A73 /* RankButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E56E5441B3269A3002D0A73 /* RankButton.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 7E56E5211B326398002D0A73 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 7E56E4FF1B326398002D0A73 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 7E56E5061B326398002D0A73; 28 | remoteInfo = ZPRankButton; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 7E56E5071B326398002D0A73 /* ZPRankButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZPRankButton.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 7E56E50B1B326398002D0A73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 7E56E50C1B326398002D0A73 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 7E56E50E1B326398002D0A73 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 7E56E50F1B326398002D0A73 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 7E56E5111B326398002D0A73 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 7E56E5121B326398002D0A73 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 7E56E5151B326398002D0A73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 7E56E5171B326398002D0A73 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 7E56E51A1B326398002D0A73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 7E56E5201B326398002D0A73 /* ZPRankButtonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZPRankButtonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 7E56E5251B326398002D0A73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 7E56E5261B326398002D0A73 /* ZPRankButtonTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZPRankButtonTests.m; sourceTree = ""; }; 46 | 7E56E5401B3269A3002D0A73 /* mall_dingzhi@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "mall_dingzhi@2x.png"; sourceTree = ""; }; 47 | 7E56E5411B3269A3002D0A73 /* mall_leimu@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "mall_leimu@2x.png"; sourceTree = ""; }; 48 | 7E56E5431B3269A3002D0A73 /* RankButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RankButton.h; sourceTree = ""; }; 49 | 7E56E5441B3269A3002D0A73 /* RankButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RankButton.m; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 7E56E5041B326398002D0A73 /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | 7E56E51D1B326398002D0A73 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | /* End PBXFrameworksBuildPhase section */ 68 | 69 | /* Begin PBXGroup section */ 70 | 7E56E4FE1B326398002D0A73 = { 71 | isa = PBXGroup; 72 | children = ( 73 | 7E56E5091B326398002D0A73 /* ZPRankButton */, 74 | 7E56E5231B326398002D0A73 /* ZPRankButtonTests */, 75 | 7E56E5081B326398002D0A73 /* Products */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 7E56E5081B326398002D0A73 /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 7E56E5071B326398002D0A73 /* ZPRankButton.app */, 83 | 7E56E5201B326398002D0A73 /* ZPRankButtonTests.xctest */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | 7E56E5091B326398002D0A73 /* ZPRankButton */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 7E56E50E1B326398002D0A73 /* AppDelegate.h */, 92 | 7E56E50F1B326398002D0A73 /* AppDelegate.m */, 93 | 7E56E5111B326398002D0A73 /* ViewController.h */, 94 | 7E56E5121B326398002D0A73 /* ViewController.m */, 95 | 7E56E5401B3269A3002D0A73 /* mall_dingzhi@2x.png */, 96 | 7E56E5411B3269A3002D0A73 /* mall_leimu@2x.png */, 97 | 7E56E5421B3269A3002D0A73 /* ZPButtonRank */, 98 | 7E56E5141B326398002D0A73 /* Main.storyboard */, 99 | 7E56E5171B326398002D0A73 /* Images.xcassets */, 100 | 7E56E5191B326398002D0A73 /* LaunchScreen.xib */, 101 | 7E56E50A1B326398002D0A73 /* Supporting Files */, 102 | ); 103 | path = ZPRankButton; 104 | sourceTree = ""; 105 | }; 106 | 7E56E50A1B326398002D0A73 /* Supporting Files */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 7E56E50B1B326398002D0A73 /* Info.plist */, 110 | 7E56E50C1B326398002D0A73 /* main.m */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | 7E56E5231B326398002D0A73 /* ZPRankButtonTests */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 7E56E5261B326398002D0A73 /* ZPRankButtonTests.m */, 119 | 7E56E5241B326398002D0A73 /* Supporting Files */, 120 | ); 121 | path = ZPRankButtonTests; 122 | sourceTree = ""; 123 | }; 124 | 7E56E5241B326398002D0A73 /* Supporting Files */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 7E56E5251B326398002D0A73 /* Info.plist */, 128 | ); 129 | name = "Supporting Files"; 130 | sourceTree = ""; 131 | }; 132 | 7E56E5421B3269A3002D0A73 /* ZPButtonRank */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 7E56E5431B3269A3002D0A73 /* RankButton.h */, 136 | 7E56E5441B3269A3002D0A73 /* RankButton.m */, 137 | ); 138 | path = ZPButtonRank; 139 | sourceTree = ""; 140 | }; 141 | /* End PBXGroup section */ 142 | 143 | /* Begin PBXNativeTarget section */ 144 | 7E56E5061B326398002D0A73 /* ZPRankButton */ = { 145 | isa = PBXNativeTarget; 146 | buildConfigurationList = 7E56E52A1B326398002D0A73 /* Build configuration list for PBXNativeTarget "ZPRankButton" */; 147 | buildPhases = ( 148 | 7E56E5031B326398002D0A73 /* Sources */, 149 | 7E56E5041B326398002D0A73 /* Frameworks */, 150 | 7E56E5051B326398002D0A73 /* Resources */, 151 | ); 152 | buildRules = ( 153 | ); 154 | dependencies = ( 155 | ); 156 | name = ZPRankButton; 157 | productName = ZPRankButton; 158 | productReference = 7E56E5071B326398002D0A73 /* ZPRankButton.app */; 159 | productType = "com.apple.product-type.application"; 160 | }; 161 | 7E56E51F1B326398002D0A73 /* ZPRankButtonTests */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 7E56E52D1B326398002D0A73 /* Build configuration list for PBXNativeTarget "ZPRankButtonTests" */; 164 | buildPhases = ( 165 | 7E56E51C1B326398002D0A73 /* Sources */, 166 | 7E56E51D1B326398002D0A73 /* Frameworks */, 167 | 7E56E51E1B326398002D0A73 /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | 7E56E5221B326398002D0A73 /* PBXTargetDependency */, 173 | ); 174 | name = ZPRankButtonTests; 175 | productName = ZPRankButtonTests; 176 | productReference = 7E56E5201B326398002D0A73 /* ZPRankButtonTests.xctest */; 177 | productType = "com.apple.product-type.bundle.unit-test"; 178 | }; 179 | /* End PBXNativeTarget section */ 180 | 181 | /* Begin PBXProject section */ 182 | 7E56E4FF1B326398002D0A73 /* Project object */ = { 183 | isa = PBXProject; 184 | attributes = { 185 | LastUpgradeCheck = 0630; 186 | ORGANIZATIONNAME = pzheng; 187 | TargetAttributes = { 188 | 7E56E5061B326398002D0A73 = { 189 | CreatedOnToolsVersion = 6.3.2; 190 | }; 191 | 7E56E51F1B326398002D0A73 = { 192 | CreatedOnToolsVersion = 6.3.2; 193 | TestTargetID = 7E56E5061B326398002D0A73; 194 | }; 195 | }; 196 | }; 197 | buildConfigurationList = 7E56E5021B326398002D0A73 /* Build configuration list for PBXProject "ZPRankButton" */; 198 | compatibilityVersion = "Xcode 3.2"; 199 | developmentRegion = English; 200 | hasScannedForEncodings = 0; 201 | knownRegions = ( 202 | en, 203 | Base, 204 | ); 205 | mainGroup = 7E56E4FE1B326398002D0A73; 206 | productRefGroup = 7E56E5081B326398002D0A73 /* Products */; 207 | projectDirPath = ""; 208 | projectRoot = ""; 209 | targets = ( 210 | 7E56E5061B326398002D0A73 /* ZPRankButton */, 211 | 7E56E51F1B326398002D0A73 /* ZPRankButtonTests */, 212 | ); 213 | }; 214 | /* End PBXProject section */ 215 | 216 | /* Begin PBXResourcesBuildPhase section */ 217 | 7E56E5051B326398002D0A73 /* Resources */ = { 218 | isa = PBXResourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 7E56E5161B326398002D0A73 /* Main.storyboard in Resources */, 222 | 7E56E51B1B326398002D0A73 /* LaunchScreen.xib in Resources */, 223 | 7E56E5461B3269A3002D0A73 /* mall_leimu@2x.png in Resources */, 224 | 7E56E5451B3269A3002D0A73 /* mall_dingzhi@2x.png in Resources */, 225 | 7E56E5181B326398002D0A73 /* Images.xcassets in Resources */, 226 | ); 227 | runOnlyForDeploymentPostprocessing = 0; 228 | }; 229 | 7E56E51E1B326398002D0A73 /* Resources */ = { 230 | isa = PBXResourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | /* End PBXResourcesBuildPhase section */ 237 | 238 | /* Begin PBXSourcesBuildPhase section */ 239 | 7E56E5031B326398002D0A73 /* Sources */ = { 240 | isa = PBXSourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 7E56E5131B326398002D0A73 /* ViewController.m in Sources */, 244 | 7E56E5101B326398002D0A73 /* AppDelegate.m in Sources */, 245 | 7E56E50D1B326398002D0A73 /* main.m in Sources */, 246 | 7E56E5471B3269A3002D0A73 /* RankButton.m in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | 7E56E51C1B326398002D0A73 /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | 7E56E5271B326398002D0A73 /* ZPRankButtonTests.m in Sources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | /* End PBXSourcesBuildPhase section */ 259 | 260 | /* Begin PBXTargetDependency section */ 261 | 7E56E5221B326398002D0A73 /* PBXTargetDependency */ = { 262 | isa = PBXTargetDependency; 263 | target = 7E56E5061B326398002D0A73 /* ZPRankButton */; 264 | targetProxy = 7E56E5211B326398002D0A73 /* PBXContainerItemProxy */; 265 | }; 266 | /* End PBXTargetDependency section */ 267 | 268 | /* Begin PBXVariantGroup section */ 269 | 7E56E5141B326398002D0A73 /* Main.storyboard */ = { 270 | isa = PBXVariantGroup; 271 | children = ( 272 | 7E56E5151B326398002D0A73 /* Base */, 273 | ); 274 | name = Main.storyboard; 275 | sourceTree = ""; 276 | }; 277 | 7E56E5191B326398002D0A73 /* LaunchScreen.xib */ = { 278 | isa = PBXVariantGroup; 279 | children = ( 280 | 7E56E51A1B326398002D0A73 /* Base */, 281 | ); 282 | name = LaunchScreen.xib; 283 | sourceTree = ""; 284 | }; 285 | /* End PBXVariantGroup section */ 286 | 287 | /* Begin XCBuildConfiguration section */ 288 | 7E56E5281B326398002D0A73 /* Debug */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ALWAYS_SEARCH_USER_PATHS = NO; 292 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 293 | CLANG_CXX_LIBRARY = "libc++"; 294 | CLANG_ENABLE_MODULES = YES; 295 | CLANG_ENABLE_OBJC_ARC = YES; 296 | CLANG_WARN_BOOL_CONVERSION = YES; 297 | CLANG_WARN_CONSTANT_CONVERSION = YES; 298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 299 | CLANG_WARN_EMPTY_BODY = YES; 300 | CLANG_WARN_ENUM_CONVERSION = YES; 301 | CLANG_WARN_INT_CONVERSION = YES; 302 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 303 | CLANG_WARN_UNREACHABLE_CODE = YES; 304 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 305 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 306 | COPY_PHASE_STRIP = NO; 307 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | GCC_C_LANGUAGE_STANDARD = gnu99; 310 | GCC_DYNAMIC_NO_PIC = NO; 311 | GCC_NO_COMMON_BLOCKS = YES; 312 | GCC_OPTIMIZATION_LEVEL = 0; 313 | GCC_PREPROCESSOR_DEFINITIONS = ( 314 | "DEBUG=1", 315 | "$(inherited)", 316 | ); 317 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 318 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 319 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNUSED_FUNCTION = YES; 323 | GCC_WARN_UNUSED_VARIABLE = YES; 324 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 325 | MTL_ENABLE_DEBUG_INFO = YES; 326 | ONLY_ACTIVE_ARCH = YES; 327 | SDKROOT = iphoneos; 328 | }; 329 | name = Debug; 330 | }; 331 | 7E56E5291B326398002D0A73 /* Release */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ALWAYS_SEARCH_USER_PATHS = NO; 335 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 336 | CLANG_CXX_LIBRARY = "libc++"; 337 | CLANG_ENABLE_MODULES = YES; 338 | CLANG_ENABLE_OBJC_ARC = YES; 339 | CLANG_WARN_BOOL_CONVERSION = YES; 340 | CLANG_WARN_CONSTANT_CONVERSION = YES; 341 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 342 | CLANG_WARN_EMPTY_BODY = YES; 343 | CLANG_WARN_ENUM_CONVERSION = YES; 344 | CLANG_WARN_INT_CONVERSION = YES; 345 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 346 | CLANG_WARN_UNREACHABLE_CODE = YES; 347 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 348 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 349 | COPY_PHASE_STRIP = NO; 350 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 351 | ENABLE_NS_ASSERTIONS = NO; 352 | ENABLE_STRICT_OBJC_MSGSEND = YES; 353 | GCC_C_LANGUAGE_STANDARD = gnu99; 354 | GCC_NO_COMMON_BLOCKS = YES; 355 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 356 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 357 | GCC_WARN_UNDECLARED_SELECTOR = YES; 358 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 359 | GCC_WARN_UNUSED_FUNCTION = YES; 360 | GCC_WARN_UNUSED_VARIABLE = YES; 361 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 362 | MTL_ENABLE_DEBUG_INFO = NO; 363 | SDKROOT = iphoneos; 364 | VALIDATE_PRODUCT = YES; 365 | }; 366 | name = Release; 367 | }; 368 | 7E56E52B1B326398002D0A73 /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 372 | INFOPLIST_FILE = ZPRankButton/Info.plist; 373 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | }; 376 | name = Debug; 377 | }; 378 | 7E56E52C1B326398002D0A73 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 382 | INFOPLIST_FILE = ZPRankButton/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 384 | PRODUCT_NAME = "$(TARGET_NAME)"; 385 | }; 386 | name = Release; 387 | }; 388 | 7E56E52E1B326398002D0A73 /* Debug */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | BUNDLE_LOADER = "$(TEST_HOST)"; 392 | FRAMEWORK_SEARCH_PATHS = ( 393 | "$(SDKROOT)/Developer/Library/Frameworks", 394 | "$(inherited)", 395 | ); 396 | GCC_PREPROCESSOR_DEFINITIONS = ( 397 | "DEBUG=1", 398 | "$(inherited)", 399 | ); 400 | INFOPLIST_FILE = ZPRankButtonTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZPRankButton.app/ZPRankButton"; 404 | }; 405 | name = Debug; 406 | }; 407 | 7E56E52F1B326398002D0A73 /* Release */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | BUNDLE_LOADER = "$(TEST_HOST)"; 411 | FRAMEWORK_SEARCH_PATHS = ( 412 | "$(SDKROOT)/Developer/Library/Frameworks", 413 | "$(inherited)", 414 | ); 415 | INFOPLIST_FILE = ZPRankButtonTests/Info.plist; 416 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZPRankButton.app/ZPRankButton"; 419 | }; 420 | name = Release; 421 | }; 422 | /* End XCBuildConfiguration section */ 423 | 424 | /* Begin XCConfigurationList section */ 425 | 7E56E5021B326398002D0A73 /* Build configuration list for PBXProject "ZPRankButton" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | 7E56E5281B326398002D0A73 /* Debug */, 429 | 7E56E5291B326398002D0A73 /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | 7E56E52A1B326398002D0A73 /* Build configuration list for PBXNativeTarget "ZPRankButton" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | 7E56E52B1B326398002D0A73 /* Debug */, 438 | 7E56E52C1B326398002D0A73 /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | defaultConfigurationName = Release; 442 | }; 443 | 7E56E52D1B326398002D0A73 /* Build configuration list for PBXNativeTarget "ZPRankButtonTests" */ = { 444 | isa = XCConfigurationList; 445 | buildConfigurations = ( 446 | 7E56E52E1B326398002D0A73 /* Debug */, 447 | 7E56E52F1B326398002D0A73 /* Release */, 448 | ); 449 | defaultConfigurationIsVisible = 0; 450 | defaultConfigurationName = Release; 451 | }; 452 | /* End XCConfigurationList section */ 453 | }; 454 | rootObject = 7E56E4FF1B326398002D0A73 /* Project object */; 455 | } 456 | -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/project.xcworkspace/xcshareddata/ZPRankButton.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | A0F8C06F-C09C-49CE-AC37-2EFCAE28327D 9 | IDESourceControlProjectName 10 | ZPRankButton 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 5821650690EC95BCACDDC9FC6EBA64D303CF0E20 14 | https://github.com/GeekZP/ZPRankButton.git 15 | 16 | IDESourceControlProjectPath 17 | ZPRankButton.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 5821650690EC95BCACDDC9FC6EBA64D303CF0E20 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/GeekZP/ZPRankButton.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 5821650690EC95BCACDDC9FC6EBA64D303CF0E20 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 5821650690EC95BCACDDC9FC6EBA64D303CF0E20 36 | IDESourceControlWCCName 37 | ZPRankButton 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/project.xcworkspace/xcuserdata/zhengpeng.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekZP/ZPRankButton/eb599ba71d73b8bf2346caeafe3e6201a58bd2e7/ZPRankButton.xcodeproj/project.xcworkspace/xcuserdata/zhengpeng.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/xcuserdata/zhengpeng.xcuserdatad/xcschemes/ZPRankButton.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /ZPRankButton.xcodeproj/xcuserdata/zhengpeng.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZPRankButton.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 7E56E5061B326398002D0A73 16 | 17 | primary 18 | 19 | 20 | 7E56E51F1B326398002D0A73 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ZPRankButton/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZPRankButton 4 | // 5 | // Created by 郑鹏 on 15/6/18. 6 | // Copyright (c) 2015年 pzheng. 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 | -------------------------------------------------------------------------------- /ZPRankButton/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZPRankButton 4 | // 5 | // Created by 郑鹏 on 15/6/18. 6 | // Copyright (c) 2015年 pzheng. 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 | -------------------------------------------------------------------------------- /ZPRankButton/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ZPRankButton/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 29 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ZPRankButton/Images.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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ZPRankButton/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.pzheng.$(PRODUCT_NAME:rfc1034identifier) 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 | 40 | 41 | -------------------------------------------------------------------------------- /ZPRankButton/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZPButtonRank 4 | 5 | 6 | // 联系开发者 QQ 1397819210 7 | // Email 1397819210@qq.com 8 | 9 | 10 | // Created by 郑鹏 on 15/6/8. 11 | // Copyright (c) 2015年 pzheng. All rights reserved. 12 | // 13 | 14 | #import 15 | 16 | @interface ViewController : UIViewController 17 | 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /ZPRankButton/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZPButtonRank 4 | 5 | 6 | // 联系开发者 QQ 1397819210 7 | // Email 1397819210@qq.com 8 | 9 | 10 | // Created by 郑鹏 on 15/6/8. 11 | // Copyright (c) 2015年 pzheng. All rights reserved. 12 | // 13 | #import "RankButton.h" 14 | #import "ViewController.h" 15 | #define MYScreenWidth [UIScreen mainScreen].bounds.size.width 16 | @interface ViewController () 17 | { 18 | RankButton *btn1; 19 | RankButton *btn3; 20 | RankButton *btn; 21 | RankButton *btn4; 22 | RankButton *norbtn; 23 | } 24 | @property (weak, nonatomic) IBOutlet UILabel *baseL; 25 | @end 26 | 27 | @implementation ViewController 28 | 29 | - (void)viewDidLoad { 30 | [super viewDidLoad]; 31 | 32 | 33 | 34 | 35 | btn1= [RankButton buttonWithType:UIButtonTypeCustom]; 36 | btn1.frame = CGRectMake(20, CGRectGetMaxY(_baseL.frame)+20, MYScreenWidth-40, 90); 37 | [btn1 setImage:[UIImage imageNamed:@"mall_leimu"] forState:UIControlStateNormal]; 38 | btn1.layer.borderWidth = 0.5; 39 | //图文排列的类型 40 | btn1.type = buttonTypeNormal; 41 | //图文间的间距 42 | btn1.picTileRange = 10; 43 | //基于图片来计算边距 44 | btn1.alignType = buttonAlignWithPic; 45 | btn1.picToViewRange = 30; 46 | [btn1 setTitle:@"测试1" forState:UIControlStateNormal]; 47 | [self.view addSubview:btn1]; 48 | 49 | 50 | btn3= [RankButton buttonWithType:UIButtonTypeCustom]; 51 | btn3.frame = CGRectMake(20 , CGRectGetMaxY(btn1.frame)+20, MYScreenWidth-40, 90); 52 | [btn3 setImage:[UIImage imageNamed:@"mall_leimu"] forState:UIControlStateNormal]; 53 | btn3.layer.borderWidth = 0.5; 54 | btn3.picTileRange = 20; 55 | btn3.type = buttonTypePicRight; 56 | btn3.alignType = buttonAlignWithPic; 57 | btn3.picToViewRange = 10; 58 | [btn3 setTitle:@"测试" forState:UIControlStateNormal]; 59 | [self.view addSubview:btn3]; 60 | 61 | 62 | norbtn= [RankButton buttonWithType:UIButtonTypeCustom]; 63 | norbtn.frame = CGRectMake(20, CGRectGetMaxY(btn3.frame)+20, MYScreenWidth-40, 90); 64 | [norbtn setImage:[UIImage imageNamed:@"mall_leimu"] forState:UIControlStateNormal]; 65 | norbtn.layer.borderWidth = 0.5; 66 | #warning 下面这句话如果不写的默认是居中 67 | // norbtn.picTileRange = 10; 68 | // norbtn.type = buttonTypeNormal; 69 | // norbtn.alignType = buttonAlignWithPic; 70 | // norbtn.picToViewRange = 0; 71 | [norbtn setTitle:@"测试1" forState:UIControlStateNormal]; 72 | [self.view addSubview:norbtn]; 73 | 74 | btn = [RankButton buttonWithType:UIButtonTypeCustom]; 75 | btn.frame = CGRectMake(20 , CGRectGetMaxY(norbtn.frame)+20, (MYScreenWidth-60)/2, 150); 76 | [btn setImage:[UIImage imageNamed:@"mall_leimu"] forState:UIControlStateNormal]; 77 | btn.layer.borderWidth = 0.5; 78 | btn.picTileRange = 55; //设置图片和文字之间的间距 79 | btn.type = buttonTypePictBottom; //选择图文排列类型 80 | [btn setTitle:@"测试" forState:UIControlStateNormal]; 81 | [self.view addSubview:btn]; 82 | 83 | 84 | btn4= [RankButton buttonWithType:UIButtonTypeCustom]; 85 | btn4.frame = CGRectMake(CGRectGetMaxX(btn.frame)+10 , CGRectGetMaxY(norbtn.frame)+20, (MYScreenWidth-60)/2, 150); 86 | [btn4 setImage:[UIImage imageNamed:@"mall_dingzhi"] forState:UIControlStateNormal]; 87 | btn4.layer.borderWidth = 0.5; 88 | btn4.picTileRange = 15; 89 | btn4.type = buttonTypePicTop; 90 | [btn4 setTitle:@"测试" forState:UIControlStateNormal]; 91 | [self.view addSubview:btn4]; 92 | 93 | } 94 | 95 | 96 | - (void)didReceiveMemoryWarning { 97 | [super didReceiveMemoryWarning]; 98 | } 99 | 100 | @end 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /ZPRankButton/ZPButtonRank/RankButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // RankButton.h 3 | // ZPButtonRank 4 | 5 | 6 | // 联系开发者 QQ 1397819210 7 | // Email 1397819210@qq.com 8 | 9 | 10 | // Created by 郑鹏 on 15/6/8. 11 | // Copyright (c) 2015年 pzheng. All rights reserved. 12 | // 13 | 14 | #import 15 | 16 | typedef enum : NSUInteger { 17 | buttonTypeNormal, //默认 左边图 右边文字 (可不写) 18 | buttonTypePicTop, // 图片在上面 文字在下面 19 | buttonTypePicRight, // 图片在右边 文字在左边 20 | buttonTypePictBottom //文字在上面 图片在下面 21 | } ButtonType; 22 | 23 | typedef enum : NSUInteger { 24 | buttonAlignWithNormal, //默认 (可不写) 25 | buttonAlignWithPic, //以图片为基准进行调整距离边缘的位置 26 | buttonAlignWithTitle //以文字为基准进行调整距离边缘的位置 27 | } ButtonAlignType; //图文排版(只做了图文左右排列的支持 上下排列的整体位置调整 后期加) 28 | 29 | @interface RankButton : UIButton 30 | 31 | @property (nonatomic,assign) ButtonType type; 32 | 33 | @property (nonatomic,assign) ButtonAlignType alignType; 34 | 35 | //图片文字之间的间距 36 | @property (nonatomic,assign) NSInteger picTileRange; 37 | 38 | //以图片为基准,设置图片距离边缘的位置 39 | @property (nonatomic,assign) NSInteger picToViewRange; 40 | 41 | 42 | @end 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /ZPRankButton/ZPButtonRank/RankButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // RankButton.m 3 | // ZPButtonRank 4 | 5 | 6 | // 联系开发者 QQ 1397819210 7 | // Email 1397819210@qq.com 8 | 9 | 10 | // Created by 郑鹏 on 15/6/8. 11 | // Copyright (c) 2015年 pzheng. All rights reserved. 12 | // 13 | 14 | #import "RankButton.h" 15 | 16 | @implementation RankButton 17 | 18 | - (id)initWithFrame:(CGRect)frame 19 | { 20 | self = [super initWithFrame:frame]; 21 | if (self) { 22 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 23 | self.titleLabel.font = [UIFont systemFontOfSize:14]; 24 | [self setTitleColor:[UIColor colorWithRed:0.44f green:0.44f blue:0.44f alpha:1.00f] forState:UIControlStateNormal]; 25 | [self setTitleColor:[UIColor colorWithRed:0.64f green:0.64f blue:0.64f alpha:1.00f] forState:UIControlStateHighlighted]; 26 | } 27 | return self; 28 | } 29 | 30 | 31 | 32 | -(void)layoutSubviews { 33 | [super layoutSubviews]; 34 | 35 | switch (_type) { 36 | case buttonTypeNormal: 37 | { 38 | CGPoint center = self.imageView.center; 39 | CGRect newFrame = [self titleLabel].frame; 40 | CGPoint tcenter = self.titleLabel.center; 41 | CGRect imaFrame = [self imageView].frame; 42 | if (_alignType == buttonAlignWithNormal) { 43 | center.x = imaFrame.size.width/2 + (self.frame.size.width - (imaFrame.size.width+newFrame.size.width+_picTileRange))/2; 44 | 45 | center.y = self.frame.size.height/2; 46 | self.imageView.center = center; 47 | newFrame.origin.x = center.x+imaFrame.size.height/2 + _picTileRange; 48 | 49 | self.titleLabel.frame = newFrame; 50 | } 51 | else if (_alignType == buttonAlignWithPic) { 52 | center.x = imaFrame.size.width/2 + _picToViewRange; 53 | self.imageView.center = center; 54 | 55 | newFrame.origin.x = center.x+imaFrame.size.height/2 + _picTileRange; 56 | self.titleLabel.frame = newFrame; 57 | } 58 | else if (_alignType == buttonAlignWithTitle) 59 | { 60 | tcenter.x = self.frame.size.width- newFrame.size.width/2 - _picToViewRange; 61 | tcenter.y = self.frame.size.height/2; 62 | self.titleLabel.center = tcenter; 63 | 64 | center.x = tcenter.x-newFrame.size.width/2-_picTileRange-imaFrame.size.width/2; 65 | self.imageView.center = center; 66 | } 67 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 68 | } 69 | break; 70 | case buttonTypePicTop: 71 | { 72 | CGPoint center = self.imageView.center; 73 | CGRect newFrame = [self titleLabel].frame; 74 | if (_alignType == buttonAlignWithPic) 75 | { 76 | 77 | } 78 | else if (_alignType == buttonAlignWithTitle) 79 | { 80 | 81 | } 82 | else 83 | { 84 | center.x = self.frame.size.width/2; 85 | center.y = self.imageView.frame.size.height/2+(self.frame.size.height - (self.imageView.frame.size.height+newFrame.size.height+5+_picTileRange))/2; 86 | self.imageView.center = center; 87 | 88 | newFrame.origin.x = 0; 89 | newFrame.origin.y = center.y+self.imageView.frame.size.height/2 + 5+_picTileRange; 90 | newFrame.size.width = self.frame.size.width; 91 | 92 | self.titleLabel.frame = newFrame; 93 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 94 | } 95 | } 96 | break; 97 | case buttonTypePicRight: 98 | { 99 | CGPoint center = self.titleLabel.center; 100 | CGRect newFrame = [self imageView].frame; 101 | CGPoint imacenter = self.imageView.center; 102 | CGRect tFrame = [self titleLabel].frame; 103 | 104 | if (_alignType == buttonAlignWithPic) 105 | { 106 | imacenter.x = self.frame.size.width-newFrame.size.width/2-_picToViewRange; 107 | self.imageView.center = imacenter; 108 | 109 | center.x = imacenter.x-newFrame.size.width/2-_picTileRange-tFrame.size.width/2; 110 | self.titleLabel.center = center; 111 | } 112 | else if (_alignType == buttonAlignWithTitle) 113 | { 114 | center.x = self.titleLabel.frame.size.width/2 + _picToViewRange; 115 | self.titleLabel.center = center; 116 | 117 | newFrame.origin.x = center.x+self.titleLabel.frame.size.width/2+_picTileRange; 118 | self.imageView.frame = newFrame; 119 | } 120 | else 121 | { 122 | center.x = self.titleLabel.frame.size.width/2 + (self.frame.size.width - (self.titleLabel.frame.size.width+newFrame.size.width+5+_picTileRange))/2; 123 | self.titleLabel.center = center; 124 | 125 | newFrame.origin.x = center.x+self.titleLabel.frame.size.width/2+5+_picTileRange; 126 | self.imageView.frame = newFrame; 127 | } 128 | } 129 | break; 130 | case buttonTypePictBottom: 131 | { 132 | if (_alignType == buttonAlignWithPic) { 133 | 134 | } 135 | else if (_alignType == buttonAlignWithTitle) 136 | { 137 | 138 | } 139 | else 140 | { 141 | CGPoint center = self.titleLabel.center; 142 | CGRect newFrame = [self imageView].frame; 143 | 144 | center.x = self.frame.size.width/2; 145 | center.y = self.titleLabel.frame.size.height/2+(self.frame.size.height-self.titleLabel.frame.size.height - newFrame.size.height - 5 - _picTileRange)/2; 146 | self.titleLabel.center = center; 147 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 148 | 149 | newFrame.origin.x = (self.frame.size.width-newFrame.size.width)/2; 150 | newFrame.origin.y = center.y+5+_picTileRange; 151 | self.imageView.frame = newFrame; 152 | } 153 | } 154 | break; 155 | default: 156 | break; 157 | } 158 | } 159 | 160 | @end 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /ZPRankButton/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZPRankButton 4 | // 5 | // Created by 郑鹏 on 15/6/18. 6 | // Copyright (c) 2015年 pzheng. 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 | -------------------------------------------------------------------------------- /ZPRankButton/mall_dingzhi@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekZP/ZPRankButton/eb599ba71d73b8bf2346caeafe3e6201a58bd2e7/ZPRankButton/mall_dingzhi@2x.png -------------------------------------------------------------------------------- /ZPRankButton/mall_leimu@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekZP/ZPRankButton/eb599ba71d73b8bf2346caeafe3e6201a58bd2e7/ZPRankButton/mall_leimu@2x.png -------------------------------------------------------------------------------- /ZPRankButtonTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.pzheng.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ZPRankButtonTests/ZPRankButtonTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZPRankButtonTests.m 3 | // ZPRankButtonTests 4 | // 5 | // Created by 郑鹏 on 15/6/18. 6 | // Copyright (c) 2015年 pzheng. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ZPRankButtonTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation ZPRankButtonTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /效果图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeekZP/ZPRankButton/eb599ba71d73b8bf2346caeafe3e6201a58bd2e7/效果图.png --------------------------------------------------------------------------------