├── .gitignore ├── CONTRIBUTING.md ├── ImageCenterButton-demo.gif ├── ImageCenterButton.podspec ├── ImageCenterButton ├── ImageCenterButton.h └── ImageCenterButton.m ├── ImageCenterButtonDemo ├── ImageCenterButtonDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── ImageCenterButtonDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── avatar.imageset │ │ │ ├── Contents.json │ │ │ └── avatar.png │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── ImageCenterButtonDemoTests │ ├── ImageCenterButtonDemoTests.m │ └── Info.plist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute 2 | 3 | 1. Fork it 4 | 1. Clone your project 5 | 1. Create your feature branch (`git checkout -b my-feature`) 6 | 1. Commit your changes (`git commit -am 'Add some feature'`) 7 | 1. Push to the branch (`git push origin my-feature`) 8 | 1. Create new Pull Request -------------------------------------------------------------------------------- /ImageCenterButton-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliThink/ImageCenterButton/5503a8eda2eb1040f320052b0282c446834a8246/ImageCenterButton-demo.gif -------------------------------------------------------------------------------- /ImageCenterButton.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ImageCenterButton" 3 | s.version = "0.1.4" 4 | s.summary = "An UIButton with TopImage and BottomLabel" 5 | s.homepage = "https://github.com/AliThink/ImageCenterButton" 6 | s.license = "MIT" 7 | s.author = { "AliThink" => "cloudsthinker@126.com" } 8 | s.source = { :git => "https://github.com/AliThink/ImageCenterButton.git", :tag => "v0.1.4" } 9 | s.source_files = "ImageCenterButton/**/*.{h,m}" 10 | s.platform = :ios, '7.0' 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /ImageCenterButton/ImageCenterButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCenterBtn.h 3 | // ButtonTopImage 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. All rights reserved. 7 | // 8 | 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | 11 | // Copyright (c) 2015 AliThink 12 | // 13 | // Permission is hereby granted, free of charge, to any person obtaining a copy 14 | // of this software and associated documentation files (the "Software"), to deal 15 | // in the Software without restriction, including without limitation the rights 16 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | // copies of the Software, and to permit persons to whom the Software is 18 | // furnished to do so, subject to the following conditions: 19 | // 20 | // The above copyright notice and this permission notice shall be included in 21 | // all copies or substantial portions of the Software. 22 | // 23 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | // THE SOFTWARE. 30 | 31 | 32 | #import 33 | 34 | IB_DESIGNABLE 35 | 36 | @interface ImageCenterButton : UIButton 37 | 38 | // Round Image 39 | @property(nonatomic) IBInspectable BOOL imageIsRound; 40 | // Highlighted Image Alpha 41 | @property(nonatomic) IBInspectable CGFloat highlightedImageAlpha; 42 | // Image Padding 43 | @property(nonatomic) IBInspectable CGFloat padding; 44 | // Border width 45 | @property(nonatomic) IBInspectable CGFloat borderWidth; 46 | // Spacing between imageview and textlabel 47 | @property(nonatomic) IBInspectable CGFloat imageTextSpace; 48 | // Maximum imageview size 49 | @property(nonatomic) IBInspectable CGSize imageViewMaxSize; 50 | // Button backgroundHighlighted 51 | @property(nonatomic, strong) IBInspectable UIColor *backgroundHighlightedColor; 52 | // Button backgroundNormal 53 | @property(nonatomic, strong) IBInspectable UIColor *backgroundNormalColor; 54 | // Border Color 55 | @property(nonatomic, strong) IBInspectable UIColor *borderColor; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /ImageCenterButton/ImageCenterButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCenterBtn.m 3 | // ButtonTopImage 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. All rights reserved. 7 | // 8 | 9 | // This code is distributed under the terms and conditions of the MIT license. 10 | 11 | // Copyright (c) 2015 AliThink 12 | // 13 | // Permission is hereby granted, free of charge, to any person obtaining a copy 14 | // of this software and associated documentation files (the "Software"), to deal 15 | // in the Software without restriction, including without limitation the rights 16 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | // copies of the Software, and to permit persons to whom the Software is 18 | // furnished to do so, subject to the following conditions: 19 | // 20 | // The above copyright notice and this permission notice shall be included in 21 | // all copies or substantial portions of the Software. 22 | // 23 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | // THE SOFTWARE. 30 | 31 | 32 | #import "ImageCenterButton.h" 33 | 34 | #define IMAGECENTERBUTTON_IMAGE_TEXT_SPACING 10.0 35 | #define IMAGECENTERBUTTON_TITLE_MIN_HEIGHT 14.0 36 | #define IMAGECENTERBUTTON_PADDING_MIN 8.0 37 | 38 | @implementation ImageCenterButton 39 | 40 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 41 | self = [super initWithCoder:aDecoder]; 42 | if (self) { 43 | [self addAction]; 44 | } 45 | return self; 46 | } 47 | 48 | - (instancetype)init { 49 | self = [super init]; 50 | if (self) { 51 | [self addAction]; 52 | } 53 | return self; 54 | } 55 | 56 | - (instancetype)initWithFrame:(CGRect)frame { 57 | self = [super initWithFrame:frame]; 58 | if (self) { 59 | [self addAction]; 60 | } 61 | return self; 62 | } 63 | 64 | - (void)addAction { 65 | [self addTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchDown]; 66 | [self addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside]; 67 | [self addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpOutside]; 68 | [self addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchCancel]; 69 | } 70 | 71 | - (void)layoutSubviews { 72 | [super layoutSubviews]; 73 | 74 | self.adjustsImageWhenHighlighted = NO; 75 | 76 | if (!self.padding) { 77 | self.padding = IMAGECENTERBUTTON_PADDING_MIN; 78 | } 79 | 80 | if (!self.imageTextSpace) { 81 | self.imageTextSpace = IMAGECENTERBUTTON_IMAGE_TEXT_SPACING; 82 | } 83 | 84 | [self.titleLabel sizeToFit]; 85 | CGFloat titleLabelHeight = self.titleLabel.frame.size.height; 86 | if (titleLabelHeight == 0) { 87 | titleLabelHeight = IMAGECENTERBUTTON_TITLE_MIN_HEIGHT; 88 | } 89 | 90 | CGFloat imageMaxHeight = self.frame.size.height - titleLabelHeight - self.imageTextSpace - self.padding * 2; 91 | CGFloat imageMaxWidth = self.frame.size.width - self.padding * 2; 92 | 93 | if (self.imageViewMaxSize.height) { 94 | imageMaxHeight = self.imageViewMaxSize.height; 95 | } 96 | if (self.imageViewMaxSize.width) { 97 | imageMaxWidth = self.imageViewMaxSize.width; 98 | } 99 | 100 | //Set ImageView Threshold 101 | if (self.imageView.frame.size.height > imageMaxHeight) { 102 | CGRect newImageView = self.imageView.frame; 103 | newImageView.size = CGSizeMake(imageMaxHeight / self.imageView.frame.size.height * self.imageView.frame.size.width, imageMaxHeight); 104 | self.imageView.frame = newImageView; 105 | } 106 | 107 | if (self.imageView.frame.size.width > imageMaxWidth) { 108 | CGRect newImageView = self.imageView.frame; 109 | newImageView.size = CGSizeMake(imageMaxWidth , imageMaxWidth / self.imageView.frame.size.width * self.imageView.frame.size.height); 110 | self.imageView.frame = newImageView; 111 | } 112 | 113 | CGFloat totalHeight = self.imageView.frame.size.height + self.imageTextSpace + titleLabelHeight; 114 | 115 | //Center image 116 | CGPoint center = self.imageView.center; 117 | center.x = self.frame.size.width / 2.0; 118 | center.y = self.frame.size.height / 2.0 - totalHeight / 2.0 + self.imageView.frame.size.height / 2.0; 119 | self.imageView.center = center; 120 | 121 | if (self.imageIsRound) { 122 | self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2.0; 123 | } 124 | 125 | CGRect titleLabelFrame = self.titleLabel.frame; 126 | titleLabelFrame.size = CGSizeMake(self.frame.size.width, titleLabelHeight); 127 | self.titleLabel.frame = titleLabelFrame; 128 | 129 | //Center text 130 | CGPoint titleCenter = self.titleLabel.center; 131 | titleCenter.x = self.frame.size.width / 2.0; 132 | titleCenter.y = self.imageView.center.y + self.imageView.frame.size.height / 2.0 + self.imageTextSpace + titleLabelHeight / 2.0; 133 | self.titleLabel.center = titleCenter; 134 | 135 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 136 | 137 | if (self.borderWidth) { 138 | self.layer.borderWidth = self.borderWidth; 139 | } 140 | 141 | if (self.borderColor) { 142 | self.layer.borderColor = self.borderColor.CGColor; 143 | } 144 | } 145 | 146 | - (void)pressed:(UIButton *)btn { 147 | if (self.highlightedImageAlpha) { 148 | [self.imageView setAlpha:self.highlightedImageAlpha]; 149 | } 150 | 151 | if (self.backgroundHighlightedColor) { 152 | [btn setBackgroundColor:self.backgroundHighlightedColor]; 153 | } else { 154 | [btn setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]]; 155 | } 156 | } 157 | 158 | - (void)touchUp:(UIButton *)btn { 159 | [self.imageView setAlpha:1.0]; 160 | 161 | if (self.backgroundNormalColor) { 162 | [btn setBackgroundColor:self.backgroundNormalColor]; 163 | } else { 164 | [btn setBackgroundColor:[UIColor whiteColor]]; 165 | } 166 | } 167 | 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BB0357AD1BA9A2EF00AD1E40 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BB0357AC1BA9A2EF00AD1E40 /* main.m */; }; 11 | BB0357B01BA9A2EF00AD1E40 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BB0357AF1BA9A2EF00AD1E40 /* AppDelegate.m */; }; 12 | BB0357B31BA9A2EF00AD1E40 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BB0357B21BA9A2EF00AD1E40 /* ViewController.m */; }; 13 | BB0357B61BA9A2EF00AD1E40 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BB0357B41BA9A2EF00AD1E40 /* Main.storyboard */; }; 14 | BB0357B81BA9A2EF00AD1E40 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BB0357B71BA9A2EF00AD1E40 /* Images.xcassets */; }; 15 | BB0357BB1BA9A2EF00AD1E40 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB0357B91BA9A2EF00AD1E40 /* LaunchScreen.xib */; }; 16 | BB0357C71BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BB0357C61BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.m */; }; 17 | BB0357D31BA9A30100AD1E40 /* ImageCenterButton.m in Sources */ = {isa = PBXBuildFile; fileRef = BB0357D21BA9A30100AD1E40 /* ImageCenterButton.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | BB0357C11BA9A2EF00AD1E40 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = BB03579F1BA9A2EF00AD1E40 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = BB0357A61BA9A2EF00AD1E40; 26 | remoteInfo = ImageCenterButtonDemo; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | BB0357A71BA9A2EF00AD1E40 /* ImageCenterButtonDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageCenterButtonDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | BB0357AB1BA9A2EF00AD1E40 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | BB0357AC1BA9A2EF00AD1E40 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | BB0357AE1BA9A2EF00AD1E40 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | BB0357AF1BA9A2EF00AD1E40 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | BB0357B11BA9A2EF00AD1E40 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | BB0357B21BA9A2EF00AD1E40 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | BB0357B51BA9A2EF00AD1E40 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | BB0357B71BA9A2EF00AD1E40 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 40 | BB0357BA1BA9A2EF00AD1E40 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 41 | BB0357C01BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ImageCenterButtonDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | BB0357C51BA9A2EF00AD1E40 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | BB0357C61BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImageCenterButtonDemoTests.m; sourceTree = ""; }; 44 | BB0357D11BA9A30100AD1E40 /* ImageCenterButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCenterButton.h; sourceTree = ""; }; 45 | BB0357D21BA9A30100AD1E40 /* ImageCenterButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCenterButton.m; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | BB0357A41BA9A2EF00AD1E40 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | BB0357BD1BA9A2EF00AD1E40 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | BB03579E1BA9A2EF00AD1E40 = { 67 | isa = PBXGroup; 68 | children = ( 69 | BB0357D01BA9A30100AD1E40 /* ImageCenterButton */, 70 | BB0357A91BA9A2EF00AD1E40 /* ImageCenterButtonDemo */, 71 | BB0357C31BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests */, 72 | BB0357A81BA9A2EF00AD1E40 /* Products */, 73 | ); 74 | sourceTree = ""; 75 | }; 76 | BB0357A81BA9A2EF00AD1E40 /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | BB0357A71BA9A2EF00AD1E40 /* ImageCenterButtonDemo.app */, 80 | BB0357C01BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.xctest */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | BB0357A91BA9A2EF00AD1E40 /* ImageCenterButtonDemo */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | BB0357AE1BA9A2EF00AD1E40 /* AppDelegate.h */, 89 | BB0357AF1BA9A2EF00AD1E40 /* AppDelegate.m */, 90 | BB0357B11BA9A2EF00AD1E40 /* ViewController.h */, 91 | BB0357B21BA9A2EF00AD1E40 /* ViewController.m */, 92 | BB0357B41BA9A2EF00AD1E40 /* Main.storyboard */, 93 | BB0357B71BA9A2EF00AD1E40 /* Images.xcassets */, 94 | BB0357B91BA9A2EF00AD1E40 /* LaunchScreen.xib */, 95 | BB0357AA1BA9A2EF00AD1E40 /* Supporting Files */, 96 | ); 97 | path = ImageCenterButtonDemo; 98 | sourceTree = ""; 99 | }; 100 | BB0357AA1BA9A2EF00AD1E40 /* Supporting Files */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | BB0357AB1BA9A2EF00AD1E40 /* Info.plist */, 104 | BB0357AC1BA9A2EF00AD1E40 /* main.m */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | BB0357C31BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | BB0357C61BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.m */, 113 | BB0357C41BA9A2EF00AD1E40 /* Supporting Files */, 114 | ); 115 | path = ImageCenterButtonDemoTests; 116 | sourceTree = ""; 117 | }; 118 | BB0357C41BA9A2EF00AD1E40 /* Supporting Files */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | BB0357C51BA9A2EF00AD1E40 /* Info.plist */, 122 | ); 123 | name = "Supporting Files"; 124 | sourceTree = ""; 125 | }; 126 | BB0357D01BA9A30100AD1E40 /* ImageCenterButton */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | BB0357D11BA9A30100AD1E40 /* ImageCenterButton.h */, 130 | BB0357D21BA9A30100AD1E40 /* ImageCenterButton.m */, 131 | ); 132 | name = ImageCenterButton; 133 | path = ../ImageCenterButton; 134 | sourceTree = ""; 135 | }; 136 | /* End PBXGroup section */ 137 | 138 | /* Begin PBXNativeTarget section */ 139 | BB0357A61BA9A2EF00AD1E40 /* ImageCenterButtonDemo */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = BB0357CA1BA9A2EF00AD1E40 /* Build configuration list for PBXNativeTarget "ImageCenterButtonDemo" */; 142 | buildPhases = ( 143 | BB0357A31BA9A2EF00AD1E40 /* Sources */, 144 | BB0357A41BA9A2EF00AD1E40 /* Frameworks */, 145 | BB0357A51BA9A2EF00AD1E40 /* Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | ); 151 | name = ImageCenterButtonDemo; 152 | productName = ImageCenterButtonDemo; 153 | productReference = BB0357A71BA9A2EF00AD1E40 /* ImageCenterButtonDemo.app */; 154 | productType = "com.apple.product-type.application"; 155 | }; 156 | BB0357BF1BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = BB0357CD1BA9A2EF00AD1E40 /* Build configuration list for PBXNativeTarget "ImageCenterButtonDemoTests" */; 159 | buildPhases = ( 160 | BB0357BC1BA9A2EF00AD1E40 /* Sources */, 161 | BB0357BD1BA9A2EF00AD1E40 /* Frameworks */, 162 | BB0357BE1BA9A2EF00AD1E40 /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | BB0357C21BA9A2EF00AD1E40 /* PBXTargetDependency */, 168 | ); 169 | name = ImageCenterButtonDemoTests; 170 | productName = ImageCenterButtonDemoTests; 171 | productReference = BB0357C01BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.xctest */; 172 | productType = "com.apple.product-type.bundle.unit-test"; 173 | }; 174 | /* End PBXNativeTarget section */ 175 | 176 | /* Begin PBXProject section */ 177 | BB03579F1BA9A2EF00AD1E40 /* Project object */ = { 178 | isa = PBXProject; 179 | attributes = { 180 | LastUpgradeCheck = 0640; 181 | ORGANIZATIONNAME = AliThink; 182 | TargetAttributes = { 183 | BB0357A61BA9A2EF00AD1E40 = { 184 | CreatedOnToolsVersion = 6.4; 185 | }; 186 | BB0357BF1BA9A2EF00AD1E40 = { 187 | CreatedOnToolsVersion = 6.4; 188 | TestTargetID = BB0357A61BA9A2EF00AD1E40; 189 | }; 190 | }; 191 | }; 192 | buildConfigurationList = BB0357A21BA9A2EF00AD1E40 /* Build configuration list for PBXProject "ImageCenterButtonDemo" */; 193 | compatibilityVersion = "Xcode 3.2"; 194 | developmentRegion = English; 195 | hasScannedForEncodings = 0; 196 | knownRegions = ( 197 | en, 198 | Base, 199 | ); 200 | mainGroup = BB03579E1BA9A2EF00AD1E40; 201 | productRefGroup = BB0357A81BA9A2EF00AD1E40 /* Products */; 202 | projectDirPath = ""; 203 | projectRoot = ""; 204 | targets = ( 205 | BB0357A61BA9A2EF00AD1E40 /* ImageCenterButtonDemo */, 206 | BB0357BF1BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests */, 207 | ); 208 | }; 209 | /* End PBXProject section */ 210 | 211 | /* Begin PBXResourcesBuildPhase section */ 212 | BB0357A51BA9A2EF00AD1E40 /* Resources */ = { 213 | isa = PBXResourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | BB0357B61BA9A2EF00AD1E40 /* Main.storyboard in Resources */, 217 | BB0357BB1BA9A2EF00AD1E40 /* LaunchScreen.xib in Resources */, 218 | BB0357B81BA9A2EF00AD1E40 /* Images.xcassets in Resources */, 219 | ); 220 | runOnlyForDeploymentPostprocessing = 0; 221 | }; 222 | BB0357BE1BA9A2EF00AD1E40 /* Resources */ = { 223 | isa = PBXResourcesBuildPhase; 224 | buildActionMask = 2147483647; 225 | files = ( 226 | ); 227 | runOnlyForDeploymentPostprocessing = 0; 228 | }; 229 | /* End PBXResourcesBuildPhase section */ 230 | 231 | /* Begin PBXSourcesBuildPhase section */ 232 | BB0357A31BA9A2EF00AD1E40 /* Sources */ = { 233 | isa = PBXSourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | BB0357B31BA9A2EF00AD1E40 /* ViewController.m in Sources */, 237 | BB0357B01BA9A2EF00AD1E40 /* AppDelegate.m in Sources */, 238 | BB0357D31BA9A30100AD1E40 /* ImageCenterButton.m in Sources */, 239 | BB0357AD1BA9A2EF00AD1E40 /* main.m in Sources */, 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | BB0357BC1BA9A2EF00AD1E40 /* Sources */ = { 244 | isa = PBXSourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | BB0357C71BA9A2EF00AD1E40 /* ImageCenterButtonDemoTests.m in Sources */, 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | /* End PBXSourcesBuildPhase section */ 252 | 253 | /* Begin PBXTargetDependency section */ 254 | BB0357C21BA9A2EF00AD1E40 /* PBXTargetDependency */ = { 255 | isa = PBXTargetDependency; 256 | target = BB0357A61BA9A2EF00AD1E40 /* ImageCenterButtonDemo */; 257 | targetProxy = BB0357C11BA9A2EF00AD1E40 /* PBXContainerItemProxy */; 258 | }; 259 | /* End PBXTargetDependency section */ 260 | 261 | /* Begin PBXVariantGroup section */ 262 | BB0357B41BA9A2EF00AD1E40 /* Main.storyboard */ = { 263 | isa = PBXVariantGroup; 264 | children = ( 265 | BB0357B51BA9A2EF00AD1E40 /* Base */, 266 | ); 267 | name = Main.storyboard; 268 | sourceTree = ""; 269 | }; 270 | BB0357B91BA9A2EF00AD1E40 /* LaunchScreen.xib */ = { 271 | isa = PBXVariantGroup; 272 | children = ( 273 | BB0357BA1BA9A2EF00AD1E40 /* Base */, 274 | ); 275 | name = LaunchScreen.xib; 276 | sourceTree = ""; 277 | }; 278 | /* End PBXVariantGroup section */ 279 | 280 | /* Begin XCBuildConfiguration section */ 281 | BB0357C81BA9A2EF00AD1E40 /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ALWAYS_SEARCH_USER_PATHS = NO; 285 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 286 | CLANG_CXX_LIBRARY = "libc++"; 287 | CLANG_ENABLE_MODULES = YES; 288 | CLANG_ENABLE_OBJC_ARC = YES; 289 | CLANG_WARN_BOOL_CONVERSION = YES; 290 | CLANG_WARN_CONSTANT_CONVERSION = YES; 291 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 299 | COPY_PHASE_STRIP = NO; 300 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | GCC_C_LANGUAGE_STANDARD = gnu99; 303 | GCC_DYNAMIC_NO_PIC = NO; 304 | GCC_NO_COMMON_BLOCKS = YES; 305 | GCC_OPTIMIZATION_LEVEL = 0; 306 | GCC_PREPROCESSOR_DEFINITIONS = ( 307 | "DEBUG=1", 308 | "$(inherited)", 309 | ); 310 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 311 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 312 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 313 | GCC_WARN_UNDECLARED_SELECTOR = YES; 314 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 315 | GCC_WARN_UNUSED_FUNCTION = YES; 316 | GCC_WARN_UNUSED_VARIABLE = YES; 317 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 318 | MTL_ENABLE_DEBUG_INFO = YES; 319 | ONLY_ACTIVE_ARCH = YES; 320 | SDKROOT = iphoneos; 321 | }; 322 | name = Debug; 323 | }; 324 | BB0357C91BA9A2EF00AD1E40 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 329 | CLANG_CXX_LIBRARY = "libc++"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_WARN_BOOL_CONVERSION = YES; 333 | CLANG_WARN_CONSTANT_CONVERSION = YES; 334 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 335 | CLANG_WARN_EMPTY_BODY = YES; 336 | CLANG_WARN_ENUM_CONVERSION = YES; 337 | CLANG_WARN_INT_CONVERSION = YES; 338 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 339 | CLANG_WARN_UNREACHABLE_CODE = YES; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 342 | COPY_PHASE_STRIP = NO; 343 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 344 | ENABLE_NS_ASSERTIONS = NO; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_NO_COMMON_BLOCKS = YES; 348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 350 | GCC_WARN_UNDECLARED_SELECTOR = YES; 351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_VARIABLE = YES; 354 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 355 | MTL_ENABLE_DEBUG_INFO = NO; 356 | SDKROOT = iphoneos; 357 | VALIDATE_PRODUCT = YES; 358 | }; 359 | name = Release; 360 | }; 361 | BB0357CB1BA9A2EF00AD1E40 /* Debug */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 365 | INFOPLIST_FILE = ImageCenterButtonDemo/Info.plist; 366 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 367 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 368 | PRODUCT_NAME = "$(TARGET_NAME)"; 369 | }; 370 | name = Debug; 371 | }; 372 | BB0357CC1BA9A2EF00AD1E40 /* Release */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 376 | INFOPLIST_FILE = ImageCenterButtonDemo/Info.plist; 377 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 378 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | }; 381 | name = Release; 382 | }; 383 | BB0357CE1BA9A2EF00AD1E40 /* Debug */ = { 384 | isa = XCBuildConfiguration; 385 | buildSettings = { 386 | BUNDLE_LOADER = "$(TEST_HOST)"; 387 | FRAMEWORK_SEARCH_PATHS = ( 388 | "$(SDKROOT)/Developer/Library/Frameworks", 389 | "$(inherited)", 390 | ); 391 | GCC_PREPROCESSOR_DEFINITIONS = ( 392 | "DEBUG=1", 393 | "$(inherited)", 394 | ); 395 | INFOPLIST_FILE = ImageCenterButtonDemoTests/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 397 | PRODUCT_NAME = "$(TARGET_NAME)"; 398 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ImageCenterButtonDemo.app/ImageCenterButtonDemo"; 399 | }; 400 | name = Debug; 401 | }; 402 | BB0357CF1BA9A2EF00AD1E40 /* Release */ = { 403 | isa = XCBuildConfiguration; 404 | buildSettings = { 405 | BUNDLE_LOADER = "$(TEST_HOST)"; 406 | FRAMEWORK_SEARCH_PATHS = ( 407 | "$(SDKROOT)/Developer/Library/Frameworks", 408 | "$(inherited)", 409 | ); 410 | INFOPLIST_FILE = ImageCenterButtonDemoTests/Info.plist; 411 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 412 | PRODUCT_NAME = "$(TARGET_NAME)"; 413 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ImageCenterButtonDemo.app/ImageCenterButtonDemo"; 414 | }; 415 | name = Release; 416 | }; 417 | /* End XCBuildConfiguration section */ 418 | 419 | /* Begin XCConfigurationList section */ 420 | BB0357A21BA9A2EF00AD1E40 /* Build configuration list for PBXProject "ImageCenterButtonDemo" */ = { 421 | isa = XCConfigurationList; 422 | buildConfigurations = ( 423 | BB0357C81BA9A2EF00AD1E40 /* Debug */, 424 | BB0357C91BA9A2EF00AD1E40 /* Release */, 425 | ); 426 | defaultConfigurationIsVisible = 0; 427 | defaultConfigurationName = Release; 428 | }; 429 | BB0357CA1BA9A2EF00AD1E40 /* Build configuration list for PBXNativeTarget "ImageCenterButtonDemo" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | BB0357CB1BA9A2EF00AD1E40 /* Debug */, 433 | BB0357CC1BA9A2EF00AD1E40 /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | }; 437 | BB0357CD1BA9A2EF00AD1E40 /* Build configuration list for PBXNativeTarget "ImageCenterButtonDemoTests" */ = { 438 | isa = XCConfigurationList; 439 | buildConfigurations = ( 440 | BB0357CE1BA9A2EF00AD1E40 /* Debug */, 441 | BB0357CF1BA9A2EF00AD1E40 /* Release */, 442 | ); 443 | defaultConfigurationIsVisible = 0; 444 | }; 445 | /* End XCConfigurationList section */ 446 | }; 447 | rootObject = BB03579F1BA9A2EF00AD1E40 /* Project object */; 448 | } 449 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ImageCenterButtonDemo 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. 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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ImageCenterButtonDemo 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. 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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/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 | 43 | 64 | 82 | 100 | 121 | 139 | 157 | 178 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/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 | } -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/Images.xcassets/avatar.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "avatar.png" 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 | } -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/Images.xcassets/avatar.imageset/avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliThink/ImageCenterButton/5503a8eda2eb1040f320052b0282c446834a8246/ImageCenterButtonDemo/ImageCenterButtonDemo/Images.xcassets/avatar.imageset/avatar.png -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.alithink.$(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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ImageCenterButtonDemo 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ImageCenterButtonDemo 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ImageCenterButton.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet UIView *containerView; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | } 23 | 24 | - (void)viewDidAppear:(BOOL)animated { 25 | [super viewDidAppear:animated]; 26 | 27 | // Manual setup 28 | //[self configView]; 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | - (void)configView { 37 | [self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 38 | NSUInteger rows = 3.0; 39 | NSUInteger cols = 3.0; 40 | CGFloat unitWidth = self.containerView.bounds.size.width / cols; 41 | CGFloat unitHeight = self.containerView.bounds.size.height / rows; 42 | 43 | for (int row = 0; row < rows; row++) { 44 | for (int col = 0; col < cols; col ++) { 45 | ImageCenterButton *imageCenterButton = [[ImageCenterButton alloc] init]; 46 | imageCenterButton.frame = CGRectMake(col * unitWidth, row * unitHeight, unitWidth, unitHeight); 47 | [imageCenterButton setImage:[UIImage imageNamed:@"avatar"] forState:UIControlStateNormal]; 48 | [imageCenterButton setTitle:@"AliThink" forState:UIControlStateNormal]; 49 | [imageCenterButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; 50 | imageCenterButton.titleLabel.font = [UIFont systemFontOfSize: 16]; 51 | imageCenterButton.backgroundColor = [UIColor whiteColor]; 52 | imageCenterButton.imageIsRound = YES; 53 | imageCenterButton.padding = 14; 54 | imageCenterButton.layer.borderColor = [[UIColor lightGrayColor] CGColor]; 55 | imageCenterButton.layer.borderWidth = 0.5; 56 | [self.containerView addSubview:imageCenterButton]; 57 | } 58 | } 59 | 60 | } 61 | 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ImageCenterButtonDemo 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. 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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemoTests/ImageCenterButtonDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCenterButtonDemoTests.m 3 | // ImageCenterButtonDemoTests 4 | // 5 | // Created by AliThink on 15/9/16. 6 | // Copyright (c) 2015年 AliThink. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ImageCenterButtonDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation ImageCenterButtonDemoTests 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 | -------------------------------------------------------------------------------- /ImageCenterButtonDemo/ImageCenterButtonDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.alithink.$(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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 AliThink 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImageCenterButton 2 | 3 | 4 | 5 | An UIButton with TopImage and BottomLabel 6 | ## What 7 | 8 | ImageCenterButton is a subclass of UIButton. Use it you can make a button with imageview upon the button textlabel easily. 9 | 10 | ## Features 11 | 12 | * Dynamic image frame generated 13 | * Spacing between imageview and textlabel customization 14 | * Image padding customization 15 | * Round image support 16 | * Dynamic button backgroundColor customization 17 | * IB_DESIGNABLE and IBInspectable added(Andrey Yastrebov ^_^) 18 | 19 | ## CocoaPods 20 | To use ImageCenterButton add the following to your Podfile 21 | 22 | pod 'ImageCenterButton' 23 | 24 | ## Usage 25 | ```objective-c 26 | // Round Image 27 | @property(nonatomic) IBInspectable BOOL imageIsRound; 28 | // Image Padding 29 | @property(nonatomic) IBInspectable CGFloat padding; 30 | // Spacing between imageview and textlabel 31 | @property(nonatomic) IBInspectable CGFloat imageTextSpace; 32 | // Maximum imageview size 33 | @property(nonatomic) IBInspectable CGSize imageViewMaxSize; 34 | // Button backgroundHighlighted 35 | @property(nonatomic, strong) IBInspectable UIColor *backgroundHighlightedColor; 36 | // Button backgroundNormal 37 | @property(nonatomic, strong) IBInspectable UIColor *backgroundNormalColor; 38 | // Border width 39 | @property(nonatomic) IBInspectable CGFloat borderWidth; 40 | // Border Color 41 | @property(nonatomic, strong) IBInspectable UIColor *borderColor; 42 | ``` 43 | 44 | ## License 45 | 46 | ImageCenterButton is available under the MIT license. See the LICENSE file for more info. 47 | 48 | --- 49 | README(Chinese) 50 | ========== 51 | 52 | ## ImageCenterButton 是什么 53 | 54 | ImageCenterButton 是UIButton的子类。可以用它很方便的生成图像在上文字标签在下的按钮。 55 | 56 | ## ImageCenterButton提供了哪些功能 57 | 58 | * 根据按钮大小动态调整图像大小 59 | * 图像与文字标签间距可定制 60 | * 图像padding可定制 61 | * 支持生成圆形图像 62 | * 按钮不同状态背景色可定制 63 | * 添加IB_DESIGNABLE IBInspectable 支持(感谢Andrey Yastrebov的支持) 64 | 65 | ## ImageCenterButton 使用配置 66 | ```objective-c 67 | // 是否将图像设置成圆形 68 | @property(nonatomic) IBInspectable BOOL imageIsRound; 69 | // 图像padding设置 70 | @property(nonatomic) IBInspectable CGFloat padding; 71 | // imageview和textlabel间距设置 72 | @property(nonatomic) IBInspectable CGFloat imageTextSpace; 73 | // imageview最大尺寸设置 74 | @property(nonatomic) IBInspectable CGSize imageViewMaxSize; 75 | // Button高亮状态背景色设置 76 | @property(nonatomic, strong) IBInspectable UIColor *backgroundHighlightedColor; 77 | // Button普通状态背景色设置 78 | @property(nonatomic, strong) IBInspectable UIColor *backgroundNormalColor; 79 | // 边框宽度设置 80 | @property(nonatomic) IBInspectable CGFloat borderWidth; 81 | // 边框颜色设置 82 | @property(nonatomic, strong) IBInspectable UIColor *borderColor; 83 | ``` 84 | 85 | ## CocoaPods 支持 86 | 87 | 你可以在 Podfile 中加入下面一行代码来使用ImageCenterButton 88 | 89 | pod 'ImageCenterButton' 90 | 91 | ## 协议 92 | 93 | ImageCenterButton 被许可在 MIT 协议下使用。查阅 LICENSE 文件来获得更多信息。 94 | --------------------------------------------------------------------------------