Skip to content

Commit

Permalink
* 修复取消按钮不显示时 UI 上的一个 Bug。另外你可以通过设置 cancelButtonTitlenil 或 `@""…
Browse files Browse the repository at this point in the history
…` 来不显示取消按钮,这是一个 Tip,并不是一个 Feature。。。

* 修正一些逻辑:

  * `cancelButtonIndex` 始终返回 `0`。

  * 除取消按钮以外的按钮自上而下 Index 从 1 递增。也就是说,无论取消按钮是否显示,Index 0 始终会被取消按钮占有。
  • Loading branch information
Leo committed Oct 22, 2016
1 parent 45c9af8 commit 40461e0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion LCActionSheet.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "LCActionSheet"
s.version = "2.5.2"
s.version = "2.6.0"
s.summary = "A simple, ornamental, but powerful action sheet! Support: http://LeoDev.me"
s.homepage = "https://github.com/iTofu/LCActionSheet"
s.license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion LCActionSheet/LCActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// GitHub: http://github.com/iTofu
// Mail: mailto:devtip@163.com
//
// V 2.5.2
// V 2.6.0

#import <UIKit/UIKit.h>

Expand Down
33 changes: 16 additions & 17 deletions LCActionSheet/LCActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ @interface LCActionSheet () <UITableViewDataSource, UITableViewDelegate, UIScrol
@property (nonatomic, weak) UIView *darkView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UITableView *tableView;
@property (nonatomic, weak) UIView *divisionView;
@property (nonatomic, weak) UIButton *cancelButton;

@property (nonatomic, weak) UIView *whiteBgView;
Expand Down Expand Up @@ -139,7 +140,7 @@ - (instancetype)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)ca

self.title = title;
self.cancelButtonTitle = cancelButtonTitle;
self.clickedHandle = clickedHandle;
self.clickedHandle = clickedHandle;
self.otherButtonTitles = tempOtherButtonTitles;

[self setupView];
Expand All @@ -165,7 +166,7 @@ - (instancetype)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)ca

self.title = title;
self.cancelButtonTitle = cancelButtonTitle;
self.clickedHandle = clickedHandle;
self.clickedHandle = clickedHandle;
self.otherButtonTitles = otherButtonTitleArray;

[self setupView];
Expand Down Expand Up @@ -256,7 +257,6 @@ - (void)setupView {
CGFloat height = self.otherButtonTitles.count * self.buttonHeight;
make.height.equalTo(@(height));
}];
// tableView.scrollEnabled = NO;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView = tableView;

Expand Down Expand Up @@ -287,6 +287,7 @@ - (void)setupView {
CGFloat height = self.cancelButtonTitle.length > 0 ? 6.0f : 0;
make.height.equalTo(@(height));
}];
self.divisionView = divisionView;

NSString *bgImagePath = [bundlePath stringByAppendingPathComponent:@"bgImage_HL@2x.png"];
UIImage *bgImage = [UIImage imageWithContentsOfFile:bgImagePath];
Expand All @@ -302,7 +303,7 @@ - (void)setupView {
[bottomView addSubview:cancelButton];
[cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bottomView);
make.top.equalTo(divisionView.mas_bottom);
make.bottom.equalTo(bottomView);

CGFloat height = self.cancelButtonTitle.length > 0 ? self.buttonHeight : 0;
make.height.equalTo(@(height));
Expand Down Expand Up @@ -382,6 +383,7 @@ - (void)setCancelButtonTitle:(NSString *)cancelButtonTitle {
_cancelButtonTitle = [cancelButtonTitle copy];

[self.cancelButton setTitle:cancelButtonTitle forState:UIControlStateNormal];
[self updateCancelButton];
}

- (void)setDestructiveButtonIndexSet:(NSSet *)destructiveButtonIndexSet {
Expand Down Expand Up @@ -478,7 +480,7 @@ - (void)setButtonHeight:(CGFloat)aButtonHeight {
}

- (NSInteger)cancelButtonIndex {
return self.cancelButtonTitle.length > 0 ? 0 : -1;
return 0;
}

- (UIFont *)titleFont {
Expand Down Expand Up @@ -597,6 +599,11 @@ - (void)updateTableView {
}

- (void)updateCancelButton {
[self.divisionView mas_updateConstraints:^(MASConstraintMaker *make) {
CGFloat height = self.cancelButtonTitle.length > 0 ? 6.0f : 0;
make.height.equalTo(@(height));
}];

[self.cancelButton mas_updateConstraints:^(MASConstraintMaker *make) {
CGFloat height = self.cancelButtonTitle.length > 0 ? self.buttonHeight : 0;
make.height.equalTo(@(height));
Expand Down Expand Up @@ -701,20 +708,16 @@ - (void)cancelButtonClicked {
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger temp = 0;
if (self.cancelButtonTitle.length > 0) {
temp = 1;
}

if ([self.delegate respondsToSelector:@selector(actionSheet:clickedButtonAtIndex:)]) {
[self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row + temp];
[self.delegate actionSheet:self clickedButtonAtIndex:indexPath.row + 1];
}

if (self.clickedHandle) {
self.clickedHandle(self, indexPath.row + temp);
self.clickedHandle(self, indexPath.row + 1);
}

[self hideWithButtonIndex:indexPath.row + temp];
[self hideWithButtonIndex:indexPath.row + 1];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Expand All @@ -738,11 +741,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.tag = indexPath.row + LC_ACTION_SHEET_CELL_TAG_INTERVAL;

if (self.destructiveButtonIndexSet) {
NSInteger temp = 0;
if (self.cancelButtonTitle.length > 0) {
temp = 1;
}
if ([self.destructiveButtonIndexSet containsObject:[NSNumber numberWithInteger:indexPath.row + temp]]) {
if ([self.destructiveButtonIndexSet containsObject:[NSNumber numberWithInteger:indexPath.row + 1]]) {
cell.titleLabel.textColor = self.destructiveButtonColor;
} else {
cell.titleLabel.textColor = self.buttonColor;
Expand Down
2 changes: 1 addition & 1 deletion LCActionSheetDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.5.2</string>
<string>2.6.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,23 @@ In me the tiger sniffs the rose.

## 版本 ChangeLog

### V 2.6.0 (2016.10.22)

* 修复取消按钮不显示时 UI 上的一个 Bug。另外你可以通过设置 `cancelButtonTitle``nil``@""` 来不显示取消按钮,这是一个 Tip,并不是一个 Feature。。。

* 修正一些逻辑:

* `cancelButtonIndex` 始终返回 `0`

* 除取消按钮以外的按钮自上而下 Index 从 1 递增。也就是说,无论取消按钮是否显示,Index 0 始终会被取消按钮占有。


### V 2.5.2 (2016.09.23)

* ~~**注:** 因 CocoaPods 对 Xcode 8 的一些问题([Issue 5661](https://github.com/CocoaPods/CocoaPods/issues/5661)[Issue 5843](https://github.com/CocoaPods/CocoaPods/issues/5843)...),暂时无法推到 CocoaPods Repo,你需要在 Podfile 进行如下的修改,直接指向当前版本即可:~~

```ruby
 # 不需要了,作者借了个 Xcode 7 的电脑去更新了……
 # 不需要了,作者借了个 Xcode 7 的电脑去更新了。。。
pod 'LCActionSheet' # , :git => 'https://github.com/iTofu/LCActionSheet.git'
```

Expand All @@ -200,7 +211,7 @@ In me the tiger sniffs the rose.

### V 2.5.0 (2016.09.05 ⚠️ 属性名变化)

* 添加 `cancenButtonIndex` 属性。在 `cancelTitle.length > 0` 的情况下始终返回 `0`,否则返回 `-1`
* 添加 `cancenButtonIndex` 属性,始终返回 `0`

```objc
@interface LCActionSheet : UIView
Expand Down

0 comments on commit 40461e0

Please sign in to comment.