Skip to content

Commit

Permalink
2.6.4.1、新增 button 点击事件 blcok,具体使用详见 demo! <br>
Browse files Browse the repository at this point in the history
  • Loading branch information
boai committed Sep 12, 2017
1 parent 642c7ab commit b6c9a2a
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 66 deletions.
2 changes: 1 addition & 1 deletion BAButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BAButton'
s.version = '2.6.3'
s.version = '2.6.4'
s.summary = '自定义 button 类!用分类全新重构 BAButton,代码配置更灵活!可以自由设置 button 的文字和图片的布局、间距、每个角的切圆角!'
s.homepage = 'https://github.com/BAHome/BAButton'
s.license = 'MIT'
Expand Down
16 changes: 4 additions & 12 deletions BAButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
C47869A81ECE8249006A55B5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C47869A71ECE8249006A55B5 /* ViewController.m */; };
C47869AB1ECE8249006A55B5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C47869A91ECE8249006A55B5 /* Main.storyboard */; };
C47869AD1ECE8249006A55B5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C47869AC1ECE8249006A55B5 /* Assets.xcassets */; };
C47869B01ECE8249006A55B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C47869AE1ECE8249006A55B5 /* LaunchScreen.storyboard */; };
C49231231ECFDD4A00B61C37 /* ViewController2.xib in Resources */ = {isa = PBXBuildFile; fileRef = C49231221ECFDD4A00B61C37 /* ViewController2.xib */; };
C49231261ECFDD6300B61C37 /* ViewController2.m in Sources */ = {isa = PBXBuildFile; fileRef = C49231251ECFDD6300B61C37 /* ViewController2.m */; };
C4BD9EBE1F3E9BFC0021C57C /* begin.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C4BD9EBD1F3E9BFC0021C57C /* begin.mp3 */; };
C4BD9EC01F3E9D110021C57C /* failure.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C4BD9EBF1F3E9D110021C57C /* failure.mp3 */; };
C4C8BFF61F022E1200D57B07 /* 条形码.jpg in Resources */ = {isa = PBXBuildFile; fileRef = C4C8BFF51F022E1200D57B07 /* 条形码.jpg */; };
C4E9341B1F67D5C8004A457A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C4E9341A1F67D5C7004A457A /* LaunchScreen.storyboard */; };
CC5C65971ED97BFB00AE184B /* UIButton+BAState.m in Sources */ = {isa = PBXBuildFile; fileRef = CC5C65941ED97BFB00AE184B /* UIButton+BAState.m */; };
CC5C65981ED97BFC00AE184B /* UIButton+BACountDown.m in Sources */ = {isa = PBXBuildFile; fileRef = CC5C65961ED97BFB00AE184B /* UIButton+BACountDown.m */; };
CC5C659C1ED97C6A00AE184B /* ViewController3.m in Sources */ = {isa = PBXBuildFile; fileRef = CC5C659A1ED97C6A00AE184B /* ViewController3.m */; };
Expand All @@ -40,7 +40,6 @@
C47869A71ECE8249006A55B5 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
C47869AA1ECE8249006A55B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
C47869AC1ECE8249006A55B5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C47869AF1ECE8249006A55B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C47869B11ECE8249006A55B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C49231211ECFD23900B61C37 /* BAButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BAButton.h; sourceTree = "<group>"; };
C49231221ECFDD4A00B61C37 /* ViewController2.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ViewController2.xib; sourceTree = "<group>"; };
Expand All @@ -49,6 +48,7 @@
C4BD9EBD1F3E9BFC0021C57C /* begin.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = begin.mp3; sourceTree = "<group>"; };
C4BD9EBF1F3E9D110021C57C /* failure.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = failure.mp3; sourceTree = "<group>"; };
C4C8BFF51F022E1200D57B07 /* 条形码.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "条形码.jpg"; sourceTree = "<group>"; };
C4E9341A1F67D5C7004A457A /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
CC5C65931ED97BFA00AE184B /* UIButton+BAState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+BAState.h"; sourceTree = "<group>"; };
CC5C65941ED97BFB00AE184B /* UIButton+BAState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+BAState.m"; sourceTree = "<group>"; };
CC5C65951ED97BFB00AE184B /* UIButton+BACountDown.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+BACountDown.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -104,8 +104,8 @@
C4BD9EBD1F3E9BFC0021C57C /* begin.mp3 */,
C4BD9EBF1F3E9D110021C57C /* failure.mp3 */,
C47869AC1ECE8249006A55B5 /* Assets.xcassets */,
C47869AE1ECE8249006A55B5 /* LaunchScreen.storyboard */,
C47869B11ECE8249006A55B5 /* Info.plist */,
C4E9341A1F67D5C7004A457A /* LaunchScreen.storyboard */,
C47869A01ECE8249006A55B5 /* Supporting Files */,
);
path = BAButton;
Expand Down Expand Up @@ -196,8 +196,8 @@
buildActionMask = 2147483647;
files = (
C4C8BFF61F022E1200D57B07 /* 条形码.jpg in Resources */,
C4E9341B1F67D5C8004A457A /* LaunchScreen.storyboard in Resources */,
C4BD9EC01F3E9D110021C57C /* failure.mp3 in Resources */,
C47869B01ECE8249006A55B5 /* LaunchScreen.storyboard in Resources */,
C47869AD1ECE8249006A55B5 /* Assets.xcassets in Resources */,
C49231231ECFDD4A00B61C37 /* ViewController2.xib in Resources */,
C47869AB1ECE8249006A55B5 /* Main.storyboard in Resources */,
Expand Down Expand Up @@ -236,14 +236,6 @@
name = Main.storyboard;
sourceTree = "<group>";
};
C47869AE1ECE8249006A55B5 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
C47869AF1ECE8249006A55B5 /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
Expand Down
Binary file not shown.
20 changes: 15 additions & 5 deletions BAButton/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand All @@ -32,18 +37,23 @@
},
{
"idiom" : "iphone",
"size" : "60x60",
"size" : "57x57",
"scale" : "1x"
},
{
"idiom" : "iphone",
"size" : "57x57",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
}
],
"info" : {
Expand Down
7 changes: 7 additions & 0 deletions BAButton/BAButton/BAButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
项目源码地址:
OC 版 :https://github.com/BAHome/BAButton
最新更新时间:2017-09-12 【倒叙】<br>
最新 Version:【Version:2.6.4】<br>
更新内容:<br>
2.6.4.1、新增 button 点击事件 blcok,具体使用详见 demo! <br>
2.6.4.2、新增 button 不同状态下的阴影设置,具体使用详见 demo! <br>
2.6.4.3、原 方法 【ba_viewPlaySoundEffectWithFileName】替换为:【ba_buttonPlaySoundEffectWithFileName】,具体使用详见 demo! <br>
最新更新时间:2017-08-17 【倒叙】<br>
最新 Version:【Version:2.6.3】<br>
更新内容:<br>
Expand Down
27 changes: 23 additions & 4 deletions BAButton/BAButton/UIButton+BAKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
BAKit_ButtonLayoutTypeRightImageRight,
};

/**
UIButton:点击事件 block 返回
@param button 当前的 button
*/
typedef void (^BAKit_UIButtonActionBlock)(UIButton * _Nonnull button);

@interface UIButton (BAKit)

/**
Expand All @@ -102,6 +109,10 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
*/
@property (nonatomic, assign) CGFloat ba_padding_inset;

/**
UIButton:点击事件 block 返回
*/
@property(nonatomic, copy) BAKit_UIButtonActionBlock ba_buttonActionBlock;

#pragma mark - 快速创建 button

Expand Down Expand Up @@ -315,7 +326,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
target:(id)target
action:(SEL)action;

#pragma mark - 自定义:button
#pragma mark - 自定义:button 颜色
/**
UIButton:自定义 button backgroundColor
Expand All @@ -334,6 +345,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
highlightedStateColor:(UIColor *)highlightedStateColor
disabledStateColor:(UIColor *)disabledStateColor;

#pragma mark - 自定义 button backgroundImage
/**
UIButton:自定义 button backgroundImage、selectedBackgroundImage、highlightedBackgroundImage
Expand All @@ -345,6 +357,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
selectedBackgroundImage:(UIImage * __nullable)selectedBackgroundImage
highlightedBackgroundImage:(UIImage * __nullable)highlightedBackgroundImage;

#pragma mark - 自定义 button image
/**
UIButton:自定义 button image、selectedImage、highlightedImage、disabledImage
Expand All @@ -358,6 +371,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
highlightedImage:(UIImage * __nullable)highlightedImage
disabledImage:(UIImage * __nullable)disabledImage;

#pragma mark - 自定义 button title
/**
UIButton:自定义 button title、selectedTitle、highlightedTitle
Expand Down Expand Up @@ -391,6 +405,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
- (void)ba_buttonSetTitleFontName:(NSString *)fontName
size:(CGFloat)size;

#pragma mark - 点击事件
/**
UIButton:自定义 button 点击事件,默认:UIControlEventTouchUpInside
Expand All @@ -402,6 +417,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
tag:(NSInteger)tag
action:(SEL)action;

#pragma mark - 布局样式 和 间距
/**
UIButton:快速设置 button 的布局样式 和 间距
Expand All @@ -410,6 +426,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
*/
- (void)ba_button_setButtonLayoutType:(BAKit_ButtonLayoutType)type padding:(CGFloat)padding;

#pragma mark - 快速切圆角
/**
UIButton:快速切圆角,注意:文字、字体大小、图片等设置一定要在设置 ba_button_setButtonLayoutType 之前设置,要不然计算会以默认字体大小计算,导致位置偏移,如果是 xib,需要要有固定 宽高,要不然 iOS 10 设置无效
Expand All @@ -431,6 +448,7 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
borderWidth:(CGFloat)borderWidth
borderColor:(UIColor *)borderColor;

#pragma mark - title 位置
/**
UIButton:title 位置
Expand All @@ -442,14 +460,15 @@ typedef NS_ENUM(NSInteger, BAKit_ButtonLayoutType) {
verticalAlignment:(UIControlContentVerticalAlignment)verticalAlignment
contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets;

#pragma mark - 给 View 添加点击音效
/**
UIView:给 View 添加点击音效(一般用于 button 按钮的点击音效),注意,此方法不带播放结束回调,如果需要播放结束回调,请将 .m 文件中的 C 函数(soundCompleteCallBack)回调复制到播放按钮的.m 里,在里面做相关处理即可
UIButton:给 button 添加点击音效(一般用于 button 按钮的点击音效),注意,此方法不带播放结束回调,如果需要播放结束回调,请将 .m 文件中的 C 函数(soundCompleteCallBack)回调复制到播放按钮的.m 里,在里面做相关处理即可
@param filename 音乐文件名称
@param isNeedShock 是否播放音效并震动
*/
- (void)ba_viewPlaySoundEffectWithFileName:(NSString *)filename
isNeedShock:(BOOL)isNeedShock;
- (void)ba_buttonPlaySoundEffectWithFileName:(NSString *)filename
isNeedShock:(BOOL)isNeedShock;

@end

Expand Down
29 changes: 29 additions & 0 deletions BAButton/BAButton/UIButton+BAKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,24 @@ - (void)ba_buttonAddTarget:(nullable id)target
[self addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}

///**
// UIButton:自定义 button 点击事件 block 返回,默认:UIControlEventTouchUpInside
//
// @param actionBlock actionBlock description
// */
//- (void)ba_buttonTouchActionBlock:(BAKit_UIButtonActionBlock)actionBlock
//{
// [self addTarget:self action:@selector(handleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//}

- (void)handleButtonAction:(UIButton *)sender
{
if (self.ba_buttonActionBlock)
{
self.ba_buttonActionBlock(sender);
}
}

/**
UIButton:快速设置 button 的布局样式 和 间距
Expand Down Expand Up @@ -869,6 +887,17 @@ - (CGFloat)ba_padding_inset
return [BAKit_Objc_getObj floatValue];
}

- (void)setBa_buttonActionBlock:(BAKit_UIButtonActionBlock)ba_buttonActionBlock
{
[self addTarget:self action:@selector(handleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
BAKit_Objc_setObj(@selector(ba_buttonActionBlock), ba_buttonActionBlock);
}

- (BAKit_UIButtonActionBlock)ba_buttonActionBlock
{
return BAKit_Objc_getObj;
}

- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
Expand Down
17 changes: 17 additions & 0 deletions BAButton/BAButton/UIButton+BAState.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (UIFont *)ba_buttonTitleLabelFontForState:(UIControlState)state;

/**
BAButton:创建圆角半径阴影,带半径、阴影颜色
@param cornerRadius 半径
@param shadowColor 阴影颜色
@param offset 偏移量
@param opacity 透明度
@param shadowRadius 模糊程度
@param state 状态
*/
- (void)ba_buttonSetRoundShadowWithCornerRadius:(CGFloat)cornerRadius
shadowColor:(UIColor *)shadowColor
offset:(CGSize)offset
opacity:(CGFloat)opacity
shadowRadius:(CGFloat)shadowRadius
forState:(UIControlState)state;

#pragma mark - 使用key-value方式设置

/**
Expand Down
Loading

0 comments on commit b6c9a2a

Please sign in to comment.