Skip to content

Commit

Permalink
more easy to use
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciusLu committed Jun 30, 2015
1 parent 0dc73b5 commit 6760ab2
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 30 deletions.
16 changes: 8 additions & 8 deletions DeformationButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
82363E581AB9273C00A4B137 /* logo_@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "logo_@2x.png"; sourceTree = "<group>"; };
8203716E1B4246780020948D /* 微博logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "微博logo@2x.png"; sourceTree = "<group>"; };
820371701B4246F40020948D /* 微信logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "微信logo@2x.png"; sourceTree = "<group>"; };
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 = "<group>"; };
82E599241AB6AB5100D6B808 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions DeformationButton/DeformationButton/DeformationButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

@property(nonatomic, retain)UIButton *forDisplayButton;

- (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor*)color;

@end
40 changes: 29 additions & 11 deletions DeformationButton/DeformationButton/DeformationButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,45 @@ @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)
self.forDisplayButton.frame = 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];
Expand All @@ -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{
Expand Down
Binary file removed DeformationButton/Resources/button_bg@2x.png
Binary file not shown.
Binary file removed DeformationButton/Resources/logo_@2x.png
Binary file not shown.
Binary file added DeformationButton/Resources/微信logo@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DeformationButton/Resources/微博logo@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions DeformationButton/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "DeformationButton.h"

@interface ViewController (){
DeformationButton *deformationBtn;
// DeformationButton *deformationBtn;
}

@end
Expand All @@ -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];
}

Expand Down
Binary file added DeformationButton2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6760ab2

Please sign in to comment.