Permalink
Browse files

fix bug & new feature

1. 增强动态性
2. 增加点击背景是否关闭的开关
3. 更新 readme
4. 更新 Demo
  • Loading branch information...
1 parent ef783ee commit aef467bbf01e14028967bc1ae5b666520992b7da @yulingtianxia committed Jul 16, 2016
@@ -102,13 +102,9 @@ - (void)setUpUI
- (void)refreshActionSheet
{
- self.bounds = CGRectMake(0, 0, self.actionSheet.sheetWidth, self.bounds.size.height);
- [[self.actionSheet valueForKeyPath:@"actionContainer"] removeFromSuperview];
- TBActionContainer *container = [[TBActionContainer alloc] initWithSheet:self.actionSheet];
- [self.actionSheet setValue:container forKeyPath:@"actionContainer"];
- [self.actionSheet addSubview:container];
[self.actionSheet setupLayout];
- [self.actionSheet setupContainerFrame];
[self.actionSheet setupStyle];
+ [self.actionSheet setupContainerFrame];
+ self.frame = CGRectMake(0, 0, self.actionSheet.sheetWidth, self.bounds.size.height);
}
@end
@@ -14,6 +14,7 @@
@interface ViewController () <TBActionSheetDelegate>
@property (nonnull,nonatomic) NSObject *leakTest;
@property (nonnull,nonatomic) ConditionerView *conditioner;
+@property (nonatomic) TBActionSheet *actionSheet;
@end
@implementation ViewController
@@ -30,21 +31,44 @@ - (void)didReceiveMemoryWarning {
}
- (IBAction)clickActionSheet:(UIButton *)sender {
- TBActionSheet *actionSheet = [[TBActionSheet alloc] initWithTitle:@"MagicalActionSheet" message:@"巴拉巴拉小魔仙,变!" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"销毁" otherButtonTitles:nil];
+ self.actionSheet = [[TBActionSheet alloc] initWithTitle:@"MagicalActionSheet" message:@"巴拉巴拉小魔仙,变!" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"销毁" otherButtonTitles:nil];
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"ConditionerView" owner:nil options:nil];
self.conditioner = views[0];
self.conditioner.frame = CGRectMake(0, 0, [TBActionSheet appearance].sheetWidth, 400);
- self.conditioner.actionSheet = actionSheet;
- actionSheet.customView = self.conditioner;
-// action.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"github"]];
+ self.conditioner.actionSheet = self.actionSheet;
+// UI Conditioner Demo
+ self.actionSheet.customView = self.conditioner;
+
+// Github Logo Demo
+// self.actionSheet.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"github"]];
+
+// // Add Buttons Dynamically Demo
+// UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+// [addBtn setTitle:@"Add Button" forState:UIControlStateNormal];
+// [addBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+// [addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
+// addBtn.frame = (CGRect){0,0,200,50};
+// [addBtn addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
+// self.actionSheet.customView = addBtn;
- [actionSheet addButtonWithTitle:@"支持 block" style:TBActionButtonStyleDefault handler:^(TBActionButton * _Nonnull button) {
- NSLog(@"%@ %@",button.currentTitle,self.leakTest);
+ __weak __typeof(ViewController *) weakSelf = self;
+ [self.actionSheet addButtonWithTitle:@"支持 block" style:TBActionButtonStyleDefault handler:^(TBActionButton * _Nonnull button) {
+ NSLog(@"%@ %@",button.currentTitle,weakSelf.leakTest);
}];
- [actionSheet show];
+
+ [self.actionSheet show];
[self.conditioner setUpUI];
}
+- (void)addButton:(UIButton *)sender{
+ static int hint = 1;
+ [self.actionSheet addButtonWithTitle:[NSString stringWithFormat:@"%d",hint]];
+ [self.actionSheet setupLayout];
+ [self.actionSheet setupContainerFrame];
+ [self.actionSheet setupStyle];
+ hint++;
+}
+
- (IBAction)clickControllerWithAlert:(UIButton *)sender {
TBAlertController *controller = [TBAlertController alertControllerWithTitle:@"TBAlertController" message:@"AlertStyle" preferredStyle:TBAlertControllerStyleAlert];
TBAlertAction *clickme = [TBAlertAction actionWithTitle:@"点我" style: TBAlertActionStyleDefault handler:^(TBAlertAction * _Nonnull action) {
View
@@ -13,6 +13,10 @@ Here is a gif showing TBActionSheet's powerful individuation:
![](images/demo.gif)
+You can add buttons on it dynamically:
+
+![](images/addButton.gif)
+
This is the iOS9 style of `TBActionSheet` running on iOS7&iPhone 4s:
![](images/iPhone4s.jpg)
@@ -140,6 +144,9 @@ The base usage is same to `UIActionSheet`. You can just replace `UIActionSheet`
@property(nonatomic) NSInteger destructiveButtonIndex; // sets destructive (red) button. -1 means none set. default is -1. ignored if only one button
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex; // -1 if no otherButtonTitles or initWithTitle:... not used
+/**
+ * 是否可见
+ */
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
/**
@@ -174,7 +181,13 @@ The base usage is same to `UIActionSheet`. You can just replace `UIActionSheet`
* 文字颜色
*/
@property(nonatomic,strong) UIColor *tintColor UI_APPEARANCE_SELECTOR;
+/**
+ * Destructive 按钮文字颜色
+ */
@property(nonatomic,strong) UIColor *destructiveButtonColor UI_APPEARANCE_SELECTOR;
+/**
+ * Cancel 按钮文字颜色
+ */
@property(nonatomic,strong) UIColor *cancelButtonColor UI_APPEARANCE_SELECTOR;
/**
* 分割线颜色
@@ -189,10 +202,14 @@ The base usage is same to `UIActionSheet`. You can just replace `UIActionSheet`
*/
@property(nonatomic) CGFloat sheetWidth UI_APPEARANCE_SELECTOR;
/**
- * 是否让背景透明
+ * 是否让 ActionSheet 背景透明
*/
@property(nonatomic, getter=isBackgroundTransparentEnabled) NSInteger backgroundTransparentEnabled UI_APPEARANCE_SELECTOR;
/**
+ * 是否点击背景后关闭 ActionSheet
+ */
+@property(nonatomic, getter=isBackgroundTouchClosureEnabled) NSInteger backgroundTouchClosureEnabled UI_APPEARANCE_SELECTOR;
+/**
* 是否启用毛玻璃效果
*/
@property(nonatomic, getter=isBlurEffectEnabled) NSInteger blurEffectEnabled UI_APPEARANCE_SELECTOR;
@@ -201,7 +218,7 @@ The base usage is same to `UIActionSheet`. You can just replace `UIActionSheet`
*/
@property(nonatomic,assign) CGFloat rectCornerRadius UI_APPEARANCE_SELECTOR;
/**
- * ActionSheet 的环境色,如果 useBlurEffect 为 YES,在 iOS7 下会与其效果混合。
+ * ActionSheet 的环境色
*/
@property(nonatomic,strong) UIColor *ambientColor UI_APPEARANCE_SELECTOR;
/**
@@ -66,7 +66,7 @@ - (void)setNormalColor:(UIColor *)normalColor
{
_normalColor = normalColor;
self.backgroundColor = normalColor;
- if (!self.highlightedColor) {
+ if (normalColor && !self.highlightedColor) {
self.highlightedColor = [UIColor colorWithWhite:0.5 alpha:0.5];
}
}
@@ -24,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)useSystemBlurEffect;
- (BOOL)useSystemBlurEffectUnderView:(UIView *)view;
+- (void)cleanTempViews;
+
@end
NS_ASSUME_NONNULL_END
@@ -14,6 +14,7 @@
@interface TBActionContainer ()
@property (weak,nonatomic) TBActionSheet *actionSheet;
+@property (nonatomic) NSMutableArray<UIView *> *tempViews;
@end
@implementation TBActionContainer
@@ -35,6 +36,7 @@ - (instancetype)initWithSheet:(TBActionSheet *)actionSheet
[self addSubview:_header];
[self addSubview:_custom];
[self addSubview:_footer];
+ _tempViews = [NSMutableArray array];
}
return self;
}
@@ -53,6 +55,7 @@ - (BOOL)useSystemBlurEffect
blurEffectView.frame = self.bounds;
blurEffectView.layer.masksToBounds = YES;
[self insertSubview:blurEffectView atIndex:0];
+ [self.tempViews addObject:blurEffectView];
return YES;
}
return NO;
@@ -75,11 +78,13 @@ - (BOOL)useSystemBlurEffectUnderView:(UIView *)view
blurEffectView.tbRectCorner = view.tbRectCorner;
[self insertSubview:blurEffectView atIndex:0];
+ [self.tempViews addObject:blurEffectView];
[blurEffectView setCornerRadius:self.actionSheet.rectCornerRadius];
[colorView setCornerRadius:self.actionSheet.rectCornerRadius];
[self insertSubview:colorView atIndex:0];
+ [self.tempViews addObject:colorView];
if ([view isKindOfClass:[TBActionButton class]]) {
TBActionButton *btn = (TBActionButton *)view;
@@ -91,4 +96,12 @@ - (BOOL)useSystemBlurEffectUnderView:(UIView *)view
return NO;
}
+- (void)cleanTempViews
+{
+ for (UIView *view in self.tempViews) {
+ [view removeFromSuperview];
+ }
+ [self.tempViews removeAllObjects];
+}
+
@end
@@ -37,6 +37,9 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic) NSInteger destructiveButtonIndex; // sets destructive (red) button. -1 means none set. default is -1. ignored if only one button
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex; // -1 if no otherButtonTitles or initWithTitle:... not used
+/**
+ * 是否可见
+ */
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
/**
@@ -71,7 +74,13 @@ NS_ASSUME_NONNULL_BEGIN
* 文字颜色
*/
@property(nonatomic,strong) UIColor *tintColor UI_APPEARANCE_SELECTOR;
+/**
+ * Destructive 按钮文字颜色
+ */
@property(nonatomic,strong) UIColor *destructiveButtonColor UI_APPEARANCE_SELECTOR;
+/**
+ * Cancel 按钮文字颜色
+ */
@property(nonatomic,strong) UIColor *cancelButtonColor UI_APPEARANCE_SELECTOR;
/**
* 分割线颜色
@@ -86,10 +95,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic) CGFloat sheetWidth UI_APPEARANCE_SELECTOR;
/**
- * 是否让背景透明
+ * 是否让 ActionSheet 背景透明
*/
@property(nonatomic, getter=isBackgroundTransparentEnabled) NSInteger backgroundTransparentEnabled UI_APPEARANCE_SELECTOR;
/**
+ * 是否点击背景后关闭 ActionSheet
+ */
+@property(nonatomic, getter=isBackgroundTouchClosureEnabled) NSInteger backgroundTouchClosureEnabled UI_APPEARANCE_SELECTOR;
+/**
* 是否启用毛玻璃效果
*/
@property(nonatomic, getter=isBlurEffectEnabled) NSInteger blurEffectEnabled UI_APPEARANCE_SELECTOR;
@@ -98,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic,assign) CGFloat rectCornerRadius UI_APPEARANCE_SELECTOR;
/**
- * ActionSheet 的环境色,如果 useBlurEffect 为 YES,在 iOS7 下会与其效果混合。
+ * ActionSheet 的环境色
*/
@property(nonatomic,strong) UIColor *ambientColor UI_APPEARANCE_SELECTOR;
/**
Oops, something went wrong.

0 comments on commit aef467b

Please sign in to comment.