diff --git a/DeformationButton.xcodeproj/project.pbxproj b/DeformationButton.xcodeproj/project.pbxproj index 4d61367..ac541f8 100644 --- a/DeformationButton.xcodeproj/project.pbxproj +++ b/DeformationButton.xcodeproj/project.pbxproj @@ -7,8 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - 82363E591AB9273C00A4B137 /* button_bg@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 82363E571AB9273C00A4B137 /* button_bg@2x.png */; }; - 82363E5A1AB9273C00A4B137 /* logo_@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 82363E581AB9273C00A4B137 /* logo_@2x.png */; }; + 8203716F1B4246780020948D /* 微博logo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8203716E1B4246780020948D /* 微博logo@2x.png */; }; + 820371711B4246F40020948D /* 微信logo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 820371701B4246F40020948D /* 微信logo@2x.png */; }; 82E599251AB6AB5100D6B808 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 82E599241AB6AB5100D6B808 /* main.m */; }; 82E599281AB6AB5100D6B808 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 82E599271AB6AB5100D6B808 /* AppDelegate.m */; }; 82E5992B1AB6AB5100D6B808 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 82E5992A1AB6AB5100D6B808 /* ViewController.m */; }; @@ -31,8 +31,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 82363E571AB9273C00A4B137 /* button_bg@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button_bg@2x.png"; sourceTree = ""; }; - 82363E581AB9273C00A4B137 /* logo_@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "logo_@2x.png"; sourceTree = ""; }; + 8203716E1B4246780020948D /* 微博logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "微博logo@2x.png"; sourceTree = ""; }; + 820371701B4246F40020948D /* 微信logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "微信logo@2x.png"; sourceTree = ""; }; 82E5991F1AB6AB5100D6B808 /* DeformationButton.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeformationButton.app; sourceTree = BUILT_PRODUCTS_DIR; }; 82E599231AB6AB5100D6B808 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 82E599241AB6AB5100D6B808 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -73,8 +73,8 @@ 82363E561AB9273C00A4B137 /* Resources */ = { isa = PBXGroup; children = ( - 82363E571AB9273C00A4B137 /* button_bg@2x.png */, - 82363E581AB9273C00A4B137 /* logo_@2x.png */, + 820371701B4246F40020948D /* 微信logo@2x.png */, + 8203716E1B4246780020948D /* 微博logo@2x.png */, ); path = Resources; sourceTree = ""; @@ -240,10 +240,10 @@ buildActionMask = 2147483647; files = ( 82E5992E1AB6AB5100D6B808 /* Main.storyboard in Resources */, - 82363E5A1AB9273C00A4B137 /* logo_@2x.png in Resources */, 82E599331AB6AB5100D6B808 /* LaunchScreen.xib in Resources */, - 82363E591AB9273C00A4B137 /* button_bg@2x.png in Resources */, 82E599301AB6AB5100D6B808 /* Images.xcassets in Resources */, + 8203716F1B4246780020948D /* 微博logo@2x.png in Resources */, + 820371711B4246F40020948D /* 微信logo@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DeformationButton/DeformationButton/DeformationButton.h b/DeformationButton/DeformationButton/DeformationButton.h index f899ec8..cef5517 100644 --- a/DeformationButton/DeformationButton/DeformationButton.h +++ b/DeformationButton/DeformationButton/DeformationButton.h @@ -18,4 +18,6 @@ @property(nonatomic, retain)UIButton *forDisplayButton; +- (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor*)color; + @end diff --git a/DeformationButton/DeformationButton/DeformationButton.m b/DeformationButton/DeformationButton/DeformationButton.m index d3fb735..73db78b 100644 --- a/DeformationButton/DeformationButton/DeformationButton.m +++ b/DeformationButton/DeformationButton/DeformationButton.m @@ -16,21 +16,15 @@ @implementation DeformationButton{ UIView *bgView; } -- (instancetype)initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor*)color { self = [super initWithFrame:frame]; if (self) { - [self initSetting]; + [self initSettingWithColor:(UIColor*)color]; } return self; } -- (void)initBtn{ - self.forDisplayButton = [[UIButton alloc]initWithFrame:self.bounds]; - self.forDisplayButton.userInteractionEnabled = NO; - [self addSubview:self.forDisplayButton]; -} - -(CGRect)frame{ CGRect frame = [super frame]; // CGRectMake((SELF_WIDTH-286)/2+146, SELF_HEIGHT-84, 140, 36) @@ -38,10 +32,29 @@ -(CGRect)frame{ return frame; } -- (void)initSetting{ +- (UIImage*)imageWithColor:(UIColor*)color cornerRadius:(CGFloat)cornerRadius{ + CGRect rect = CGRectMake(0, 0, cornerRadius*2+10, cornerRadius*2+10); + + UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; + path.lineWidth = 0; + + UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, [color CGColor]); + + [path fill]; + [path stroke]; + [path addClip]; + + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return image; +} + +- (void)initSettingWithColor:(UIColor*)color{ scale = 1.2; bgView = [[UIView alloc]initWithFrame:self.bounds]; - bgView.backgroundColor = [UIColor blueColor]; + bgView.backgroundColor = color; bgView.userInteractionEnabled = NO; bgView.hidden = YES; [self addSubview:bgView]; @@ -62,7 +75,12 @@ - (void)initSetting{ [self addTarget:self action:@selector(loadingAction) forControlEvents:UIControlEventTouchUpInside]; - [self initBtn]; + self.forDisplayButton = [[UIButton alloc]initWithFrame:self.bounds]; + self.forDisplayButton.userInteractionEnabled = NO; + [self.forDisplayButton setBackgroundImage:[[self imageWithColor:color cornerRadius:3] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal]; + [self addSubview:self.forDisplayButton]; + + self.contentColor = color; } -(void)setContentColor:(UIColor *)contentColor{ diff --git a/DeformationButton/Resources/button_bg@2x.png b/DeformationButton/Resources/button_bg@2x.png deleted file mode 100644 index e6f488d..0000000 Binary files a/DeformationButton/Resources/button_bg@2x.png and /dev/null differ diff --git a/DeformationButton/Resources/logo_@2x.png b/DeformationButton/Resources/logo_@2x.png deleted file mode 100644 index c834ac3..0000000 Binary files a/DeformationButton/Resources/logo_@2x.png and /dev/null differ diff --git "a/DeformationButton/Resources/\345\276\256\344\277\241logo@2x.png" "b/DeformationButton/Resources/\345\276\256\344\277\241logo@2x.png" new file mode 100755 index 0000000..c963765 Binary files /dev/null and "b/DeformationButton/Resources/\345\276\256\344\277\241logo@2x.png" differ diff --git "a/DeformationButton/Resources/\345\276\256\345\215\232logo@2x.png" "b/DeformationButton/Resources/\345\276\256\345\215\232logo@2x.png" new file mode 100755 index 0000000..c7bff01 Binary files /dev/null and "b/DeformationButton/Resources/\345\276\256\345\215\232logo@2x.png" differ diff --git a/DeformationButton/ViewController.m b/DeformationButton/ViewController.m index a42b3bf..11248b7 100644 --- a/DeformationButton/ViewController.m +++ b/DeformationButton/ViewController.m @@ -10,7 +10,7 @@ #import "DeformationButton.h" @interface ViewController (){ - DeformationButton *deformationBtn; +// DeformationButton *deformationBtn; } @end @@ -37,20 +37,15 @@ - (UIColor *)getColor:(NSString *)hexColor - (void)viewDidLoad { [super viewDidLoad]; - deformationBtn = [[DeformationButton alloc]initWithFrame:CGRectMake(100, 100, 140, 36)]; - deformationBtn.contentColor = [self getColor:@"52c332"]; - deformationBtn.progressColor = [UIColor whiteColor]; + DeformationButton *deformationBtn = [[DeformationButton alloc]initWithFrame:CGRectMake(100, 100, 140, 36) withColor:[self getColor:@"e13536"]]; [self.view addSubview:deformationBtn]; - - [deformationBtn.forDisplayButton setTitle:@"微信注册" forState:UIControlStateNormal]; + + [deformationBtn.forDisplayButton setTitle:@"微博注册" forState:UIControlStateNormal]; [deformationBtn.forDisplayButton.titleLabel setFont:[UIFont systemFontOfSize:15]]; [deformationBtn.forDisplayButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [deformationBtn.forDisplayButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 6, 0, 0)]; - - [deformationBtn.forDisplayButton setImage:[UIImage imageNamed:@"logo_.png"] forState:UIControlStateNormal]; - UIImage *bgImage = [UIImage imageNamed:@"button_bg.png"]; - [deformationBtn.forDisplayButton setBackgroundImage:[bgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal]; - + [deformationBtn.forDisplayButton setImage:[UIImage imageNamed:@"微博logo.png"] forState:UIControlStateNormal]; + [deformationBtn addTarget:self action:@selector(btnEvent) forControlEvents:UIControlEventTouchUpInside]; } diff --git a/DeformationButton2.gif b/DeformationButton2.gif new file mode 100644 index 0000000..a8e1d24 Binary files /dev/null and b/DeformationButton2.gif differ