diff --git a/MKAToggleButton.podspec b/MKAToggleButton.podspec index 59ac6d9..cf83954 100644 --- a/MKAToggleButton.podspec +++ b/MKAToggleButton.podspec @@ -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. diff --git a/MKAToggleButton/Resources/Info.plist b/MKAToggleButton/Resources/Info.plist index fad975a..a894f41 100644 --- a/MKAToggleButton/Resources/Info.plist +++ b/MKAToggleButton/Resources/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.3.0 + 1.3.1 CFBundleSignature ???? CFBundleVersion - 8 + 9 NSHumanReadableCopyright Copyright Hituzi Ando. All rights reserved. diff --git a/MKAToggleButton/Sources/MKAIconToggleButton.m b/MKAToggleButton/Sources/MKAIconToggleButton.m index d829c17..8b32755 100644 --- a/MKAToggleButton/Sources/MKAIconToggleButton.m +++ b/MKAToggleButton/Sources/MKAIconToggleButton.m @@ -149,6 +149,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { - (void)setTintColor:(UIColor *)color { [super setTintColor:color]; + [self reloadView]; self.tintColorCache = color; } @@ -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 @@ -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 { @@ -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; @@ -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) { diff --git a/Sample/Framework/MKAToggleButton.framework/MKAToggleButton b/Sample/Framework/MKAToggleButton.framework/MKAToggleButton index 26d3504..52267b5 100755 Binary files a/Sample/Framework/MKAToggleButton.framework/MKAToggleButton and b/Sample/Framework/MKAToggleButton.framework/MKAToggleButton differ diff --git a/Sample/Framework/MKAToggleButton.framework/Resources/Info.plist b/Sample/Framework/MKAToggleButton.framework/Resources/Info.plist index fad975a..a894f41 100755 --- a/Sample/Framework/MKAToggleButton.framework/Resources/Info.plist +++ b/Sample/Framework/MKAToggleButton.framework/Resources/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.3.0 + 1.3.1 CFBundleSignature ???? CFBundleVersion - 8 + 9 NSHumanReadableCopyright Copyright Hituzi Ando. All rights reserved. diff --git a/Sample/MKAToggleButtonSwiftSample/ViewController.swift b/Sample/MKAToggleButtonSwiftSample/ViewController.swift index b34aa22..952247f 100644 --- a/Sample/MKAToggleButtonSwiftSample/ViewController.swift +++ b/Sample/MKAToggleButtonSwiftSample/ViewController.swift @@ -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() {