Skip to content

Commit

Permalink
Fixed bugs that the image template mode is not applied until the stat…
Browse files Browse the repository at this point in the history
…e changes.
  • Loading branch information
HituziANDO committed Feb 14, 2020
1 parent 9af88f2 commit 6a9e25e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MKAToggleButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MKAToggleButton"
s.version = "1.3.0"
s.version = "1.3.1"
s.summary = "MKAToggleButton is the button has multiple states for iOS."
s.description = <<-DESC
MKAToggleButton is the button has multiple states for iOS.
Expand Down
4 changes: 2 additions & 2 deletions MKAToggleButton/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<string>1.3.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright Hituzi Ando. All rights reserved.</string>
</dict>
Expand Down
18 changes: 15 additions & 3 deletions MKAToggleButton/Sources/MKAIconToggleButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {

- (void)setTintColor:(UIColor *)color {
[super setTintColor:color];
[self reloadView];
self.tintColorCache = color;
}

Expand All @@ -161,6 +162,11 @@ - (CGRect)touchableBounds {
return rect;
}

- (void)setImageTemplate:(BOOL)imageTemplate {
_imageTemplate = imageTemplate;
[self reloadView];
}

- (void)setCurrentStateIndex:(NSUInteger)currentStateIndex {
if (currentStateIndex < 0) {
@throw [NSException exceptionWithName:NSRangeException
Expand All @@ -174,9 +180,7 @@ - (void)setCurrentStateIndex:(NSUInteger)currentStateIndex {
_currentStateIndex = 0;
}

[self setImage:[self imageAtIndex:_currentStateIndex] forState:UIControlStateNormal];
[self setTitle:[self titleAtIndex:_currentStateIndex] forState:UIControlStateNormal];
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
[self reloadView];
}

- (void)setClickHandler:(void (^)(id _Nonnull))clickHandler {
Expand All @@ -196,7 +200,9 @@ - (void)nextState {
#pragma mark - private method

- (instancetype)build {
// Set first view.
self.currentStateIndex = 0;

[self addTarget:self action:@selector(mka_click:) forControlEvents:UIControlEventTouchUpInside];

__block CGSize maxSize = CGSizeZero;
Expand Down Expand Up @@ -260,6 +266,12 @@ - (void)mka_longPress:(UILongPressGestureRecognizer *)gesture {
}
}

- (void)reloadView {
[self setImage:[self imageAtIndex:self.currentStateIndex] forState:UIControlStateNormal];
[self setTitle:[self titleAtIndex:self.currentStateIndex] forState:UIControlStateNormal];
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
}

- (nullable UIImage *)imageAtIndex:(NSUInteger)index {
if (index < self.items.count) {
if (self.isImageTemplate) {
Expand Down
Binary file modified Sample/Framework/MKAToggleButton.framework/MKAToggleButton
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<string>1.3.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright Hituzi Ando. All rights reserved.</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion Sample/MKAToggleButtonSwiftSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ViewController: UIViewController {

// Moves to next state manually.
// When the current state is last, the next state is rewinded to the first.
self.button3.nextState()
self.button4.nextState()
}

override func viewDidLayoutSubviews() {
Expand Down

0 comments on commit 6a9e25e

Please sign in to comment.